469,303 Members | 1,967 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,303 developers. It's quick & easy.

hex string into binary format?

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
Jul 18 '05 #1
3 10908
"Tertius Cronje" <Te************@postoffice.co.za> writes:
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)

--
ha************@boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
Jul 18 '05 #2
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


Jul 18 '05 #3
"Tertius Cronje" <Te************@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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by neutrino | last post: by
9 posts views Thread by gamehack | last post: by
1 post views Thread by Ripal | last post: by
reply views Thread by Tommaso Caldarola | last post: by
6 posts views Thread by aagarwal8 | last post: by
1 post views Thread by Sin Jeong-hun | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.