Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 rifling through the Monastery: (7)
As of 2014-12-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls