Alisha Alisha - 1 year ago 126
Perl Question

How do I convert decimal to hexadecimal in Perl?

How can I convert a number,

$d = 1024
, in decimal to 0xFF in hex in Perl?

variable needs to be assigned to a different variable and be printed, so for readability I required it to be in hexadecimal format.

Answer Source

1024 in decimal is not 0xFF in hex. Instead, it is 0x400.

You can use sprintf as:

$hex = sprintf("0x%X", $d)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download