hex string into binary format?

T

Tertius Cronje

Hi,

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)
x = i1 ^i2

TypeError: unsupported operand type(s) for ^: 'str' and 'str'

Many TIA
T
 
H

Harry George

Tertius Cronje said:
Hi,

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)
x = i1 ^i2

TypeError: unsupported operand type(s) for ^: 'str' and 'str'

Many TIA
T

i1=int(s1,16)
i2=int(s2,16)
 
P

Peter Hansen

Tertius said:
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)
 
T

Tim Roberts

Tertius Cronje said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top