Question

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,

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top