Reputation: 85
Is there a way to convert decimal numbers to four hex digits? For example:
Decimal: 17 => Hex: 0x0011
Decimal: 291 => Hex: 0x0123
Decimal: 4951 => Hex: 0x1357
Basically, I want to preserve the leading zeroes.
So far I have:
my $HEX_NUM = sprintf("%x", $DEC_NUM);
Is there a way to get the leading zeros without hardcoding them?
Upvotes: 0
Views: 865