I've been using bc
to convert numbers between binary to hex, octal to decimal and others.
In the following example, I was trying to convert base 16 (hex) number to binary, octal and decimal.
I don't have any problem with the first 2 attempts.
$ echo 'ibase=16; obase=2; FF' | bc
11111111
$ echo 'ibase=16; obase=8; FF' | bc
377
But when I tried to convert base 16 (hex) number to base 10 (decimal), I was getting wrong answer. The answer should be 255
$ echo 'ibase=16; obase=10; FF' | bc
FF
printf '%d\n' 0x$hex
or justecho $(( 0x$hex ))
– dave_thompson_085 Aug 26 '18 at 00:54