Lucas Rey Lucas Rey - 1 month ago 4x
Perl Question

Convert number to HEX in perl

I need to convert a number to hex in perl. I'm using the following simple code:

my $n = 10;
print sprintf("%X", $n);

That will output: A
That's correct, but I need always 2 bytes like: 0A

So for example:
90 will show 5A - 6 will show 06 - 10 will show 0A

How can I do that?

sprintf("%02X", $n)