> Hi,
> 
> is it a bug in bash?!
> 
> to convert great numbers: binary to decimal
> 
> # decimal do binary
> $ echo "obase=2;9876543212345678909876" | bc -l
> 10000101110110100010010010001010110111010110110011100111000101000110\
> 110100
> 
> # binary to decimal
> $ echo "$((2#10000101110110100010010010001010110111010110110011100111\
> 000101000110110100))"
> 7535132911068795316

You're hitting integer overflow.  If you were to try $(( 9876543212345678909876 
))
you'd get the same result.  The arithmetic expansion and arithmetic evaluation
code doesn't check for overflow.

Bash uses intmax_t (usually 64-bit) arithmetic where it can.  987654321234567890
is the largest portion of the number you supplied that can be represented in
an intmax_t without overflow.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live...Laugh...Love
Chet Ramey, ITS, CWRU    [EMAIL PROTECTED]    http://tiswww.tis.cwru.edu/~chet/


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to