What shell is this? On Linux I see:
$ bash -c 'echo $((0x15abc12345afda325))'
6538120775109288741
wrong
$ dash -c 'echo $((0x15abc12345afda325))'
9223372036854775807
wrong
$ ksh -c 'echo $((0x15abc12345afda325))'
2.49848648488188404e+19
right, but wrong output format
$ ksh -c 'printf "%d\n" $((0x15abc12345afda325))'
ksh: printf: warning: 2.49848648488188404e+19: overflow exception
9223372036854775807
$ ksh -c 'printf "%.0f\n" $((0x15abc12345afda325))'
24984864848818840399
GNU awk
$ gawk -v n=0x15abc12345afda325 'BEGIN {print strtonum(n)}'
24984864848818839552
$ gawk --bignum -v n=0x15abc12345afda325 'BEGIN {print strtonum(n)}'
24984864848818840357
Do you have bc
available?
$ hex=15abc12345afda325
$ echo "ibase=16; $hex" | bc
(standard_in) 1: syntax error
hex values need to be in upper case?
$ echo "ibase=16; ${hex^^}" | bc
24984864848818840357
Hmm, different from ksh output. WolframAlpha says 24984864848818840357
I see busybox has dc
, but sadly, it's crippled:
$ printf "%s\n" 16 i 15ABC12345AFDA325 p | dc
24984864848818840357
$ printf "%s\n" 16 i 15ABC12345AFDA325 p | busybox dc
dc: syntax error at 'i'