Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: How do I convert from decimal to hexidecimal?

( #63225=categorized answer: print w/ replies, xml ) Need Help??

Q&A > numbers > How do I convert from decimal to hexidecimal? contributed by jmcnamara

Use the X, x and # format codes in printf and sprintf:
    $num = 15;

    printf("%X\n",     $num);   # F
    printf("%x\n",     $num);   # f
    printf("%02x\n",   $num);   # 0f
    printf("%#x\n",    $num);   # 0xf
    printf("0x%02x\n", $num);   # 0x0f
The last example is excessive but it forces formatting for zero:
    printf("%#x\n",    0);      # 0
    printf("0x%02x\n", 0);      # 0x00

Comment on Answer: How do I convert from decimal to hexidecimal?
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2015-07-07 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls