Domanda

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,

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top