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,

Était-ce utile?

La 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top