Path: news.mathworks.com!not-for-mail
From: "David " <dave@bigcompany.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Manipulation of Binary Numbers
Date: Tue, 5 Feb 2008 11:01:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 46
Message-ID: <fo9fle$4an$1@fred.mathworks.com>
References: <c50dec66-3a80-4d42-922b-ddcaf5eaf357@l1g2000hsa.googlegroups.com>
Reply-To: "David " <dave@bigcompany.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202209262 4439 172.30.248.38 (5 Feb 2008 11:01:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 5 Feb 2008 11:01:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 791003
Xref: news.mathworks.com comp.soft-sys.matlab:449347


bennymacca <ben.c.mcdonald@gmail.com> wrote in message 
<c50dec66-3a80-4d42-922b-
ddcaf5eaf357@l1g2000hsa.googlegroups.com>...
> Hi
> 
> I am working with a file that contains a serial data 
stream (i.e
> binary data)
> i an then storing this data into arrays. i.e the number 
3 would look
> like [ 0 0 1 1] etc
> 
> what i want is a way of adding these numbers together. 
i.e [0 0 1 1] +
> [0 0 0 1] = [0 1 0 0]
> 
> at present, my idea is to write a short script that 
converts to
> decimal, then add the other number, then convert back to 
an array
> using dec2binvec and binvec2dec. a short function would 
do this, but i
> would like an easier way to do this.
> 
> Any ideas?
> Cheers,
> Ben

not without a lot more information.  you say you have a 
stream of binary data... this doesn't mean anything.  any 
serial data stream contains binary data, bits... but bits 
is bits, concatenting bits out of a stream may or may not 
make anything meaningful.  for instance the series of bits 
[1 0 1 0 1 1 1 1] could be the decimal number 175 
represented in 8 bits, or it could be -81 decimal 
expressed in 2's complement in 8 bits.  or it could be the 
first 8 bits of a 64 bit double precision number, or one 
color of a 24 bit pixel in a huge image.  or it could be 
one letter of a text document.  or maybe its 4 bits of one 
character and 4 bits of the next one, how do you know 
where the pieces you want to work on start and stop??  
unless you know exactly what that group of bits represent 
arbitrarily converting them to a number and doing some 
kind of operation on the resulting number may or may not 
make any sense.