struct.unpack on 64-bit platforms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nadav Samet

    struct.unpack on 64-bit platforms

    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

  • Georg Brandl

    #2
    Re: struct.unpack on 64-bit platforms

    Nadav Samet wrote:[color=blue]
    > 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?[/color]

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

    Georg

    Comment

    • Jorgen Grahn

      #3
      Re: struct.unpack on 64-bit platforms

      On 22 Jun 2006 09:30:26 -0700, Nadav Samet <thesamet@gmail .com> wrote:
      ....[color=blue]
      > 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).[/color]

      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.dyn dns.org> R'lyeh wgah'nagl fhtagn!

      Comment

      Working...