help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about bin2dec


From: Muthiah Annamalai
Subject: Re: Question about bin2dec
Date: Thu, 29 Jun 2006 06:40:20 -0700 (PDT)

Hi -

> I have some questions regarding the bin2dec function.  My understanding
> is that it converts a string of binary characters into a decimal
> number.  However, it looks to me that spaces within the string give
> rise
> to a completely different result.  As an example:
>
>> x = [1 1 1 1 0];
>> x_str = int2str(x);    %convert to string
> fmt = %1d%3d%3d%3d%3d

>> x_str
> x_str = 1  1  1  1  0
 >> bin2dec(x_str)
> ans = 4680

> However, if I type
>> bin2dec('11110')
> I get an answer of 30, which is what I would expect.  The spaces
> inbetween the characters throw the answer off from the expected result.

> Is this a bug, or a "feature"?  It seems to me that we would not want
> the result from the first method.
> -Ron
 
I think that is a 'feature'. Especially you can use it like this:
x=sprintf("%d",x);
bin2dec(x)
 
which will do the job.
 
Thanks
Muthu


Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1ยข/min.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]