Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Conversion of Columns into Decimals
Date: Mon, 10 Dec 2007 18:27:41 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 59
Message-ID: <fjk0et$e0s$1@fred.mathworks.com>
References: <fjcsag$t98$1@fred.mathworks.com> <fjcu8k$mcp$1@fred.mathworks.com> <fjd062$fjd$1@fred.mathworks.com> <fjd1sg$6nm$1@fred.mathworks.com> <fjd710$73p$1@fred.mathworks.com> <fjdfur$npn$1@fred.mathworks.com> <fji99i$70c$1@fred.mathworks.com> <fjjta0$2ev$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.fr>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197311261 14364 172.30.248.37 (10 Dec 2007 18:27:42 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 10 Dec 2007 18:27:41 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:441820


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fjjta0$2ev$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message
<fji99i$70c
> $1@fred.mathworks.com>...
> > "Roger Stafford"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in 
> > message news:fjdfur$npn$1@fred.mathworks.com...
> > > ........
> > > [m,n] = size(A);
> > > B=sum(repmat(2.^(m-1:-1:0)',1,n).*A,1);
> > 
> > Another way to write the above is:
> > 
> > A = round(rand(7, 10)); % Sample data
> > v = ((size(A, 2)-1):-1:0).';
> > B = A*2.^v
> > B - bin2dec(num2str(A)) % Should be all zeros
> > 
> > Steve Lord
> > slord@mathworks.com 
> ---------
> Hello Steve,
> 
>   It is my understanding that Alan Dinno wants to convert
the columns, not 
> the rows, of binary array A to a row of the corresponding
numerical 
> quantities, in the manner that Matt has suggested using
the 'bin2dec' 
> function.
> 
>   However, Alan has subsequently stated that he received
an error message 
> from the 'bin2dec' function to the effect that it requires
a bit string length of 
> no more than 52 bits, which would imply that his A arrays
possess more than 
> that number of rows.  Based on this, the code I sent him
was intended to 
> overcome this obstacle, though past 53 bits the results
necessarily become 
> subject to possible roundoff error.  Has 'bin2dec' been
upgraded in more 
> recent matlab versions than Alan's so as to allow more
than 52 bits input?
> 

Does he needs to sum of bits from 53th position? May be he
just has to through them out and use hex2dec.

I would like Mathworks to add a similar function hex2int or
extend the hex2dec() with optional flag for setting output
class. Once I wanted to convert hexa string to integer (16,
or 32), hex2dec is no good to scope with overflow and sign,
and it's pretty slow. I ended up doing a small C-mex file
with sscanf(... '%x').

Bruno