I am trying to convert a mac address,
mac = '00:de:34:ef:2e:f4'
into binary format. And the program i am using is,
mac = '00:de:34:ef:2e:f4'
r = mac.replace(':', '').decode('hex')
print r
But i am getting a strange output when i run this program, and the output is
$Ã$
What am i doing wrong?
I don’t think you want to use
decode, that does unicode conversion and other stuff you don’t want. Just do:Which will convert your mac address to a number. Print it with
'%012x'%nto get the hex back.Edit:
If you want to convert to binary, then just do
bin(n).