Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Convert to Hexadecimal

by sauoq (Abbot)
on May 17, 2012 at 19:00 UTC ( [id://971151]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $ perl -le 'printf( "%04x\n", 12)'
    000c
    
  2. or download this
    perl -le 'printf( "\\x%02x\\x%02x\n", 12 )' # WRONG
    \x0c\x00
    
  3. or download this
    perl -le 'printf( "\\x%02x\\x%02x\n", unpack( "C2", 12 ))' WRONG
    \x31\x32
    
  4. or download this
    perl -le 'printf( "\\x%02x\\x%02x\n", unpack( "C2", pack("S", 12)))'
    \x0c\x00
    
  5. or download this
    perl -le 'printf( "\\x%02x\\x%02x\n", unpack( "C2", pack("n", 12)))'
    \x00\x0c
    # Another way to say that . . .
    perl -le 'printf( "\\x%02x\\x%02x\n", unpack( "C2", pack("S>", 12)))'
    \x00\x0c
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://971151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found