help-octave
[Top][All Lists]
Advanced

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

Question about bin2dec


From: Ron Crummett
Subject: Question about bin2dec
Date: Wed, 28 Jun 2006 21:53:44 -0700
User-agent: Thunderbird 1.5.0.4 (X11/20060516)

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


reply via email to

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