Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to convert binary to hexadecimal

by ikegami (Pope)
on Oct 11, 2007 at 13:49 UTC ( #644230=note: print w/replies, xml ) Need Help??


in reply to How to convert binary to hexadecimal

That's a totally pointless requirement, but the following does achieve it:

$hex = sprintf('%X', oct("0b$bin"));

oct converts the binary representation of the number to a number, then sprintf '%X' converts it to its hex representation. It's never represented in decimal.

Update: Or maybe you're actually interested in converting bytes to their hex representation:

$hex = sprintf('%02X', ord($byte));

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://644230]
help
Chatterbox?
[erix]: *learn
[erix]: comic relief: how to start a riot and a fortune at the same time
[beech]: :) thats too generous to jdporter, don't start none won't be none -- there is about two decades (rounding up) worth of "ineffective" node titles -- leave the pope alone :p
[erix]: infallibility breeds inquisition

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-01-17 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (159 votes). Check out past polls.