hex string into binary format?

Tim Roberts timr at probo.com
Fri Apr 1 03:05:11 EST 2005


"Tertius Cronje" <Tertius.Cronje at postoffice.co.za> wrote:
>
>How do I get a hexvalued string to a format recognized for binary
>calculation?

You're going to be embarrassed.

>import binascii
>s1 = '1C46BE3D9F6AA820'
>s2 = '8667B5236D89CD46'
>
>i1 = binascii.unhexlify(s1)
>i2 = binascii.unhexlify(s2)
>x = i1 ^i2
>
>	TypeError: unsupported operand type(s) for ^: 'str' and 'str'

No imports at all:

s1 = '1C46BE3D9F6AA820'
s2 = '8667B5236D89CD46'
i1 = int(s1,16)
i2 = int(s2,16)
x = i1 ^ i2
print hex(x)
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list