<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153</link>
    <title>MATLAB Central Newsreader - Manipulation of Binary Numbers</title>
    <description>Feed for thread: Manipulation of Binary Numbers</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 05 Feb 2008 01:31:08 -0500</pubDate>
      <title>Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#412952</link>
      <author>bennymacca</author>
      <description>Hi&lt;br&gt;
&lt;br&gt;
I am working with a file that contains a serial data stream (i.e&lt;br&gt;
binary data)&lt;br&gt;
i an then storing this data into arrays. i.e the number 3 would look&lt;br&gt;
like [ 0 0 1 1] etc&lt;br&gt;
&lt;br&gt;
what i want is a way of adding these numbers together. i.e [0 0 1 1] +&lt;br&gt;
[0 0 0 1] = [0 1 0 0]&lt;br&gt;
&lt;br&gt;
at present, my idea is to write a short script that converts to&lt;br&gt;
decimal, then add the other number, then convert back to an array&lt;br&gt;
using dec2binvec and binvec2dec. a short function would do this, but i&lt;br&gt;
would like an easier way to do this.&lt;br&gt;
&lt;br&gt;
Any ideas?&lt;br&gt;
Cheers,&lt;br&gt;
Ben&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 05 Feb 2008 03:09:02 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#412963</link>
      <author>Roger Stafford</author>
      <description>bennymacca &amp;lt;ben.c.mcdonald@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;c50dec66-3a80-4d42-922b-&lt;br&gt;
ddcaf5eaf357@l1g2000hsa.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am working with a file that contains a serial data stream (i.e&lt;br&gt;
&amp;gt; binary data)&lt;br&gt;
&amp;gt; i an then storing this data into arrays. i.e the number 3 would look&lt;br&gt;
&amp;gt; like [ 0 0 1 1] etc&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; what i want is a way of adding these numbers together. i.e [0 0 1 1] +&lt;br&gt;
&amp;gt; [0 0 0 1] = [0 1 0 0]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; at present, my idea is to write a short script that converts to&lt;br&gt;
&amp;gt; decimal, then add the other number, then convert back to an array&lt;br&gt;
&amp;gt; using dec2binvec and binvec2dec. a short function would do this, but i&lt;br&gt;
&amp;gt; would like an easier way to do this.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any ideas?&lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Ben&lt;br&gt;
------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;I don't have dec2binvec and binvec2dec to experiment with, but I seriously &lt;br&gt;
doubt that a for-loop or while-loop operating directly on a binary vector, &lt;br&gt;
which is what you would have to replace them with, can compete with &lt;br&gt;
operation speeds for numbers in double (that is, double precision binary &lt;br&gt;
floating point) form.  Addition, subtraction, and multiplication are all done &lt;br&gt;
with great speed, since that is one of the things modern computers' &lt;br&gt;
microprocessor chips are specifically designed to do - operate on numbers &lt;br&gt;
contained in single binary registers.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;It should also be pointed out that these quantities that are loosely called &lt;br&gt;
"decimal" are actually stored in binary form, not decimal, so, in my opinion, &lt;br&gt;
calling them decimal is a misnomer.  True decimal format is used only for the &lt;br&gt;
purpose of displaying their values to users, not for internal operations.  Thus, &lt;br&gt;
the conversion processes needed to be performed by dec2binvec and &lt;br&gt;
binvec2dec should be very simple and fast.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 05 Feb 2008 05:12:22 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#412971</link>
      <author>Yumnam Kirani Singh</author>
      <description>you can do in the following way. First convert the two vectors into equivalent decimal using bin2decbin and then add togather. Convert the result back to biary vector using dec2binvec. You may need to used fliplr or wrev for your purpose.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 05 Feb 2008 10:43:07 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#413009</link>
      <author>bennymacca</author>
      <description>On Feb 5, 1:09 pm, "Roger Stafford"&lt;br&gt;
&amp;lt;ellieandrogerxy...@mindspring.com.invalid&amp;gt; wrote:&lt;br&gt;
&amp;gt; bennymacca &amp;lt;ben.c.mcdon...@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;lt;c50dec66-3a80-4d42-922b-&lt;br&gt;
&amp;gt; ddcaf5eaf...@l1g2000hsa.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Hi&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I am working with a file that contains a serial data stream (i.e&lt;br&gt;
&amp;gt; &amp;gt; binary data)&lt;br&gt;
&amp;gt; &amp;gt; i an then storing this data into arrays. i.e the number 3 would look&lt;br&gt;
&amp;gt; &amp;gt; like [ 0 0 1 1] etc&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; what i want is a way of adding these numbers together. i.e [0 0 1 1] +&lt;br&gt;
&amp;gt; &amp;gt; [0 0 0 1] = [0 1 0 0]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; at present, my idea is to write a short script that converts to&lt;br&gt;
&amp;gt; &amp;gt; decimal, then add the other number, then convert back to an array&lt;br&gt;
&amp;gt; &amp;gt; using dec2binvec and binvec2dec. a short function would do this, but i&lt;br&gt;
&amp;gt; &amp;gt; would like an easier way to do this.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Any ideas?&lt;br&gt;
&amp;gt; &amp;gt; Cheers,&lt;br&gt;
&amp;gt; &amp;gt; Ben&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ------------&lt;br&gt;
&amp;gt;   I don't have dec2binvec and binvec2dec to experiment with, but I seriously&lt;br&gt;
&amp;gt; doubt that a for-loop or while-loop operating directly on a binary vector,&lt;br&gt;
&amp;gt; which is what you would have to replace them with, can compete with&lt;br&gt;
&amp;gt; operation speeds for numbers in double (that is, double precision binary&lt;br&gt;
&amp;gt; floating point) form.  Addition, subtraction, and multiplication are all done&lt;br&gt;
&amp;gt; with great speed, since that is one of the things modern computers'&lt;br&gt;
&amp;gt; microprocessor chips are specifically designed to do - operate on numbers&lt;br&gt;
&amp;gt; contained in single binary registers.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;   It should also be pointed out that these quantities that are loosely called&lt;br&gt;
&amp;gt; "decimal" are actually stored in binary form, not decimal, so, in my opinion,&lt;br&gt;
&amp;gt; calling them decimal is a misnomer.  True decimal format is used only for the&lt;br&gt;
&amp;gt; purpose of displaying their values to users, not for internal operations.  Thus,&lt;br&gt;
&amp;gt; the conversion processes needed to be performed by dec2binvec and&lt;br&gt;
&amp;gt; binvec2dec should be very simple and fast.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
Come on roger, thats not what i was asking. of course numbers are&lt;br&gt;
stored in binary in a computer - this is a given&lt;br&gt;
What i was asking was effectively implementation of arithmetic on a&lt;br&gt;
binary DATA type. i thought this was quite obvious, but obviously not.&lt;br&gt;
i was not after a speed increase, i was after the convenience of not&lt;br&gt;
having to change from binary to integer, back to binary etc.&lt;br&gt;
&lt;br&gt;
yumnam has it right below, this is the method that i have used.&lt;br&gt;
&lt;br&gt;
cheers,&lt;br&gt;
ben&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 05 Feb 2008 11:01:02 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#413014</link>
      <author>David </author>
      <description>bennymacca &amp;lt;ben.c.mcdonald@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;c50dec66-3a80-4d42-922b-&lt;br&gt;
ddcaf5eaf357@l1g2000hsa.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am working with a file that contains a serial data &lt;br&gt;
stream (i.e&lt;br&gt;
&amp;gt; binary data)&lt;br&gt;
&amp;gt; i an then storing this data into arrays. i.e the number &lt;br&gt;
3 would look&lt;br&gt;
&amp;gt; like [ 0 0 1 1] etc&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; what i want is a way of adding these numbers together. &lt;br&gt;
i.e [0 0 1 1] +&lt;br&gt;
&amp;gt; [0 0 0 1] = [0 1 0 0]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; at present, my idea is to write a short script that &lt;br&gt;
converts to&lt;br&gt;
&amp;gt; decimal, then add the other number, then convert back to &lt;br&gt;
an array&lt;br&gt;
&amp;gt; using dec2binvec and binvec2dec. a short function would &lt;br&gt;
do this, but i&lt;br&gt;
&amp;gt; would like an easier way to do this.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any ideas?&lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Ben&lt;br&gt;
&lt;br&gt;
not without a lot more information.  you say you have a &lt;br&gt;
stream of binary data... this doesn't mean anything.  any &lt;br&gt;
serial data stream contains binary data, bits... but bits &lt;br&gt;
is bits, concatenting bits out of a stream may or may not &lt;br&gt;
make anything meaningful.  for instance the series of bits &lt;br&gt;
[1 0 1 0 1 1 1 1] could be the decimal number 175 &lt;br&gt;
represented in 8 bits, or it could be -81 decimal &lt;br&gt;
expressed in 2's complement in 8 bits.  or it could be the &lt;br&gt;
first 8 bits of a 64 bit double precision number, or one &lt;br&gt;
color of a 24 bit pixel in a huge image.  or it could be &lt;br&gt;
one letter of a text document.  or maybe its 4 bits of one &lt;br&gt;
character and 4 bits of the next one, how do you know &lt;br&gt;
where the pieces you want to work on start and stop??  &lt;br&gt;
unless you know exactly what that group of bits represent &lt;br&gt;
arbitrarily converting them to a number and doing some &lt;br&gt;
kind of operation on the resulting number may or may not &lt;br&gt;
make any sense.&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 05 Feb 2008 23:53:40 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#413153</link>
      <author>bennymacca</author>
      <description>David, you have missed my point&lt;br&gt;
&lt;br&gt;
When i meant binary data stream, i meant the bits themselves. what i&lt;br&gt;
do with them is not the issue, and is irrelevant here.&lt;br&gt;
&lt;br&gt;
all i wanted to know was the best way to perform operations on single&lt;br&gt;
bits at a time. i already know what the bits mean, but this does not&lt;br&gt;
change the arithmetic performed on then.&lt;br&gt;
&lt;br&gt;
if the binary stream was meant to be interpreted as integers or other,&lt;br&gt;
then i would have converted to that, and there would not have been a&lt;br&gt;
problem. but matlab seems to have little support for a "binary data&lt;br&gt;
type" which is what i would like.&lt;br&gt;
&lt;br&gt;
anyway, problem is solved now, thanks very much for your help&lt;br&gt;
&lt;br&gt;
David  wrote:&lt;br&gt;
&amp;gt; bennymacca &amp;lt;ben.c.mcdonald@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;c50dec66-3a80-4d42-922b-&lt;br&gt;
&amp;gt; ddcaf5eaf357@l1g2000hsa.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I am working with a file that contains a serial data&lt;br&gt;
&amp;gt; stream (i.e&lt;br&gt;
&amp;gt; &amp;gt; binary data)&lt;br&gt;
&amp;gt; &amp;gt; i an then storing this data into arrays. i.e the number&lt;br&gt;
&amp;gt; 3 would look&lt;br&gt;
&amp;gt; &amp;gt; like [ 0 0 1 1] etc&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; what i want is a way of adding these numbers together.&lt;br&gt;
&amp;gt; i.e [0 0 1 1] +&lt;br&gt;
&amp;gt; &amp;gt; [0 0 0 1] = [0 1 0 0]&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; at present, my idea is to write a short script that&lt;br&gt;
&amp;gt; converts to&lt;br&gt;
&amp;gt; &amp;gt; decimal, then add the other number, then convert back to&lt;br&gt;
&amp;gt; an array&lt;br&gt;
&amp;gt; &amp;gt; using dec2binvec and binvec2dec. a short function would&lt;br&gt;
&amp;gt; do this, but i&lt;br&gt;
&amp;gt; &amp;gt; would like an easier way to do this.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Any ideas?&lt;br&gt;
&amp;gt; &amp;gt; Cheers,&lt;br&gt;
&amp;gt; &amp;gt; Ben&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; not without a lot more information.  you say you have a&lt;br&gt;
&amp;gt; stream of binary data... this doesn't mean anything.  any&lt;br&gt;
&amp;gt; serial data stream contains binary data, bits... but bits&lt;br&gt;
&amp;gt; is bits, concatenting bits out of a stream may or may not&lt;br&gt;
&amp;gt; make anything meaningful.  for instance the series of bits&lt;br&gt;
&amp;gt; [1 0 1 0 1 1 1 1] could be the decimal number 175&lt;br&gt;
&amp;gt; represented in 8 bits, or it could be -81 decimal&lt;br&gt;
&amp;gt; expressed in 2's complement in 8 bits.  or it could be the&lt;br&gt;
&amp;gt; first 8 bits of a 64 bit double precision number, or one&lt;br&gt;
&amp;gt; color of a 24 bit pixel in a huge image.  or it could be&lt;br&gt;
&amp;gt; one letter of a text document.  or maybe its 4 bits of one&lt;br&gt;
&amp;gt; character and 4 bits of the next one, how do you know&lt;br&gt;
&amp;gt; where the pieces you want to work on start and stop??&lt;br&gt;
&amp;gt; unless you know exactly what that group of bits represent&lt;br&gt;
&amp;gt; arbitrarily converting them to a number and doing some&lt;br&gt;
&amp;gt; kind of operation on the resulting number may or may not&lt;br&gt;
&amp;gt; make any sense.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Wed, 06 Feb 2008 00:06:44 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#413155</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;74d47d21-3f70-43a0-ab8d-b58d163ffae4@l32g2000hse.googlegroups.com&amp;gt;,&lt;br&gt;
bennymacca  &amp;lt;ben.c.mcdonald@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;When i meant binary data stream, i meant the bits themselves. what i&lt;br&gt;
&amp;gt;do with them is not the issue, and is irrelevant here.&lt;br&gt;
&lt;br&gt;
&amp;gt;all i wanted to know was the best way to perform operations on single&lt;br&gt;
&amp;gt;bits at a time. i already know what the bits mean, but this does not&lt;br&gt;
&amp;gt;change the arithmetic performed on then.&lt;br&gt;
&lt;br&gt;
Your posted question was about the best way to group several bits&lt;br&gt;
in order to perform operations on the group, which is a different&lt;br&gt;
question than performing operations on single bits.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt;if the binary stream was meant to be interpreted as integers or other,&lt;br&gt;
&amp;gt;then i would have converted to that, and there would not have been a&lt;br&gt;
&amp;gt;problem. but matlab seems to have little support for a "binary data&lt;br&gt;
&amp;gt;type" which is what i would like.&lt;br&gt;
&lt;br&gt;
Matlab Fixed-Point Toolbox&lt;br&gt;
&lt;a href="http://www.mathworks.com/products/fixed/description3.html"&gt;http://www.mathworks.com/products/fixed/description3.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;The toolbox lets you use four modes for performing fixed-point arithmetic:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Fully automatic mode, enabling you to use up to 65,535 bits for the&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum or product &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Fully specified mode, letting you indicate the word length and binary&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;point location for the sum or product &lt;br&gt;
-- &lt;br&gt;
'Roberson' is my family name; my given name is 'Walter'.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Wed, 06 Feb 2008 00:29:49 -0500</pubDate>
      <title>Re: Manipulation of Binary Numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163153#413160</link>
      <author>bennymacca</author>
      <description>thanks walter,&lt;br&gt;
your right&lt;br&gt;
&lt;br&gt;
what i wanted to distinguish though is that i was working on ones and&lt;br&gt;
zeros, not on say an 8-bit integer grouped from the  binary data&lt;br&gt;
stream, in which case it would make more sense to convert the number&lt;br&gt;
first before performing operations.&lt;br&gt;
&lt;br&gt;
Regards,&lt;br&gt;
ben&lt;br&gt;
&lt;br&gt;
Walter Roberson wrote:&lt;br&gt;
&amp;gt; In article &amp;lt;74d47d21-3f70-43a0-ab8d-b58d163ffae4@l32g2000hse.googlegroups.com&amp;gt;,&lt;br&gt;
&amp;gt; bennymacca  &amp;lt;ben.c.mcdonald@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;When i meant binary data stream, i meant the bits themselves. what i&lt;br&gt;
&amp;gt; &amp;gt;do with them is not the issue, and is irrelevant here.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;all i wanted to know was the best way to perform operations on single&lt;br&gt;
&amp;gt; &amp;gt;bits at a time. i already know what the bits mean, but this does not&lt;br&gt;
&amp;gt; &amp;gt;change the arithmetic performed on then.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Your posted question was about the best way to group several bits&lt;br&gt;
&amp;gt; in order to perform operations on the group, which is a different&lt;br&gt;
&amp;gt; question than performing operations on single bits.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;if the binary stream was meant to be interpreted as integers or other,&lt;br&gt;
&amp;gt; &amp;gt;then i would have converted to that, and there would not have been a&lt;br&gt;
&amp;gt; &amp;gt;problem. but matlab seems to have little support for a "binary data&lt;br&gt;
&amp;gt; &amp;gt;type" which is what i would like.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Matlab Fixed-Point Toolbox&lt;br&gt;
&amp;gt; &lt;a href="http://www.mathworks.com/products/fixed/description3.html"&gt;http://www.mathworks.com/products/fixed/description3.html&lt;/a&gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;   The toolbox lets you use four modes for performing fixed-point arithmetic:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;     Fully automatic mode, enabling you to use up to 65,535 bits for the&lt;br&gt;
&amp;gt;     sum or product&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;     Fully specified mode, letting you indicate the word length and binary&lt;br&gt;
&amp;gt;     point location for the sum or product&lt;br&gt;
&amp;gt; --&lt;br&gt;
&amp;gt; 'Roberson' is my family name; my given name is 'Walter'.&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
