hex string into binary format?

Peter Hansen peter at engcorp.com
Thu Mar 31 11:01:44 EST 2005


Tertius Cronje wrote:
> How do I get a hexvalued string to a format recognized for binary
> calculation?
> 
> import binascii
> s1 = '1C46BE3D9F6AA820'
> s2 = '8667B5236D89CD46'
> 
> i1 = binascii.unhexlify(s1)
> i2 = binascii.unhexlify(s2)

Try this instead:
i1 = long(s1, 16)
i2 = long(s2, 16)

> x = i1 ^i2




More information about the Python-list mailing list