tags:

views:

53

answers:

1

Hi,

I'm receiving from the socket a MAC address in this format: 0024e865a023 (hex converted from binary with received-string.encode("hex"))

I would like to convert it to a user readable format like this : 00-24-e8-65-a0-23

Any easy way to do so ?

Thanks

+2  A: 

You can break apart the MAC address into an array of each block, and then join them on -:

mac = '0024e865a023'
blocks = [mac[x:x+2] for x in xrange(0, len(mac), 2)]
macFormatted = '-'.join(blocks)
Michael Mrozek