hex to decimal

hi all,

echo "ibase=16;obase=10;11" | bc

shouldn't i get 17? i am getting 11

i am trying to convert 11 (hex) to decimal

stuck!

JAK

You should set obase before ibase:

radoulov@linux-jgly:~> bc<<<'ibase=16;obase=10;11'
11
radoulov@linux-jgly:~> bc<<<'obase=10;ibase=16;11'
17

ah thx!

The problem seems not to be in "bc", but in "dc". I executed your command (which seems to be correct IMHO) with the "-c" switch (compile only) to bc and it gave me:

16i
10o
11ps.

This command list seems to be correct.

When executing this inside dc i got the same erroneous result as you (AIX 5.3 here), but when i changed the output base to "2" i got "10001", which is correct. Also, when i use "8" as output base it gave me the corect result "21". I conclude that "dc" has some systematic error.

Edit: didn't see radoulovs hint - i didn't know that. *blushes*

bakunin

ibase=16;obase=10 <--- here 10 is hexadecimal as ibase is already modified, decimal 17 ...