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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top