hex string into binary format?

Discussion in 'Python' started by Tertius Cronje, Mar 31, 2005.

  1. 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
     
    Tertius Cronje, Mar 31, 2005
    #1
    1. Advertising

  2. Tertius Cronje

    Harry George Guest

    "Tertius Cronje" <> 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)

    --

    6-6M21 BCA CompArch Design Engineering
    Phone: (425) 294-4718
     
    Harry George, Mar 31, 2005
    #2
    1. Advertising

  3. Tertius Cronje

    Peter Hansen Guest

    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
     
    Peter Hansen, Mar 31, 2005
    #3
  4. Tertius Cronje

    Tim Roberts Guest

    "Tertius Cronje" <> 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,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Apr 1, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,406
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    534
    Juha Autero
    Aug 19, 2003
  3. jack
    Replies:
    4
    Views:
    616
  4. tim

    hex string to hex value

    tim, Nov 22, 2005, in forum: Python
    Replies:
    8
    Views:
    19,140
  5. tim
    Replies:
    2
    Views:
    1,595
    Dennis Lee Bieber
    Nov 23, 2005
Loading...

Share This Page