Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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));
Comment on Re: How to convert binary to hexadecimal
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2016-05-01 10:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found