linux bc hexadecimal representation
题
I want to the following hexadecimals to be returned in 6 hex value format...
[admin@X~]$ echo "obase=16; 16777215" | bc
FFFFFF
[admin@X~]$ echo "obase=16; 0" | bc
0
[admin@X~]$
I want 0 be represented as 000000...
Any help?
Thanks,
解决方案
official answer then...
printf
does hex with leading zeros easily and you don't need any of the fancy multi-precision math from bc
so why not
printf '%06X\n' 0
printf '%06X\n' 16777215
不隶属于 StackOverflow