Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > hex string into binary format?

Reply
Thread Tools

hex string into binary format?

 
 
Tertius Cronje
Guest
Posts: n/a
 
      03-31-2005
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
 
Reply With Quote
 
 
 
 
Harry George
Guest
Posts: n/a
 
      03-31-2005
"Tertius Cronje" <(E-Mail Removed)> 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)

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      03-31-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


 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      04-01-2005
"Tertius Cronje" <(E-Mail Removed)> 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, (E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hex string to hex value tim Python 8 11-23-2005 06:27 PM
[Fwd: Re: hex string to hex value] tim Python 2 11-23-2005 07:18 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex value in string back to real hex value jack Python 4 09-08-2004 07:11 AM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments