Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Manipulation of Binary Numbers
Date: Tue, 5 Feb 2008 03:09:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <fo8k0e$6mr$1@fred.mathworks.com>
References: <c50dec66-3a80-4d42-922b-ddcaf5eaf357@l1g2000hsa.googlegroups.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202180942 6875 172.30.248.35 (5 Feb 2008 03:09:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 5 Feb 2008 03:09:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:449296


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
------------
  I don't have dec2binvec and binvec2dec to experiment with, but I seriously 
doubt that a for-loop or while-loop operating directly on a binary vector, 
which is what you would have to replace them with, can compete with 
operation speeds for numbers in double (that is, double precision binary 
floating point) form.  Addition, subtraction, and multiplication are all done 
with great speed, since that is one of the things modern computers' 
microprocessor chips are specifically designed to do - operate on numbers 
contained in single binary registers.

  It should also be pointed out that these quantities that are loosely called 
"decimal" are actually stored in binary form, not decimal, so, in my opinion, 
calling them decimal is a misnomer.  True decimal format is used only for the 
purpose of displaying their values to users, not for internal operations.  Thus, 
the conversion processes needed to be performed by dec2binvec and 
binvec2dec should be very simple and fast.

Roger Stafford