struct.unpack on 64-bit platforms

Discussion in 'Python' started by Nadav Samet, Jun 22, 2006.

  1. Nadav Samet

    Nadav Samet Guest

    Hi,

    I am trying to unpack a 32-bit unsigned integer from a string using
    struct.unpack.
    so using string.unpack('L', data) would work fine on 32-bit systems,

    But apparently, on 64-bit platforms it tries to read 64-bit unsigned
    integer (since
    that's what the C Type unsigned long means on 64-bit platforms).

    So what's the way to make it read exactly 32-bits, on all platforms?

    Thanks,
    Nadav
     
    Nadav Samet, Jun 22, 2006
    #1
    1. Advertising

  2. Nadav Samet

    Georg Brandl Guest

    Nadav Samet wrote:
    > Hi,
    >
    > I am trying to unpack a 32-bit unsigned integer from a string using
    > struct.unpack.
    > so using string.unpack('L', data) would work fine on 32-bit systems,
    >
    > But apparently, on 64-bit platforms it tries to read 64-bit unsigned
    > integer (since
    > that's what the C Type unsigned long means on 64-bit platforms).
    >
    > So what's the way to make it read exactly 32-bits, on all platforms?


    Looking into the docs, prepending your format string with "=" should
    make "L" exactly 32 bits on each platform.

    Georg
     
    Georg Brandl, Jun 22, 2006
    #2
    1. Advertising

  3. Nadav Samet

    Jorgen Grahn Guest

    On 22 Jun 2006 09:30:26 -0700, Nadav Samet <> wrote:
    ....
    > But apparently, on 64-bit platforms it tries to read 64-bit unsigned
    > integer (since
    > that's what the C Type unsigned long means on 64-bit platforms).


    On /some/ 64-bit platforms. Others let unsigned long be 32-bit and introduce
    the 64-bit 'long long' types (and 64-bit pointers).

    The term "64-bit", like "32-bit" before it, is too vague to use in technical
    discussions, IMHO.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
    \X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
     
    Jorgen Grahn, Jun 29, 2006
    #3
    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. Richard Burte

    RE: .Net Framework for 64 bit platforms

    Richard Burte, Sep 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,193
    Richard Burte
    Sep 30, 2003
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,392
    Chris Fogelklou
    Apr 20, 2004
  3. mikeSpindler

    struct.unpack() and bit operations

    mikeSpindler, Sep 23, 2004, in forum: Python
    Replies:
    2
    Views:
    579
    Peter Otten
    Sep 23, 2004
  4. Replies:
    1
    Views:
    351
    Larry Bates
    Oct 26, 2005
  5. junyoung
    Replies:
    9
    Views:
    3,111
    Arne Vajhøj
    Apr 28, 2010
Loading...

Share This Page