Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d21g2000prf.googlegroups.com!not-for-mail
From: bennymacca <ben.c.mcdonald@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Manipulation of Binary Numbers
Date: Tue, 5 Feb 2008 02:43:07 -0800 (PST)
Organization: http://groups.google.com
Lines: 56
Message-ID: <9105ea4b-ed1b-4401-bedc-8da215b12dc4@d21g2000prf.googlegroups.com>
References: <c50dec66-3a80-4d42-922b-ddcaf5eaf357@l1g2000hsa.googlegroups.com> 
NNTP-Posting-Host: 219.90.153.186
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1202208188 21463 127.0.0.1 (5 Feb 2008 10:43:08 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 5 Feb 2008 10:43:08 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d21g2000prf.googlegroups.com; posting-host=219.90.153.186; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.11) 
Xref: news.mathworks.com comp.soft-sys.matlab:449342


On Feb 5, 1:09 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> bennymacca <ben.c.mcdon...@gmail.com> wrote in message
>
> <c50dec66-3a80-4d42-922b-
> ddcaf5eaf...@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

Come on roger, thats not what i was asking. of course numbers are
stored in binary in a computer - this is a given
What i was asking was effectively implementation of arithmetic on a
binary DATA type. i thought this was quite obvious, but obviously not.
i was not after a speed increase, i was after the convenience of not
having to change from binary to integer, back to binary etc.

yumnam has it right below, this is the method that i have used.

cheers,
ben