470,614 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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

Jun 22 '06 #1
2 5409
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
Jun 22 '06 #2
On 22 Jun 2006 09:30:26 -0700, Nadav Samet <th******@gmail.com> 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!
Jun 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Matthew Barnes | last post: by
2 posts views Thread by Angelo Secchi | last post: by
5 posts views Thread by grant | last post: by
2 posts views Thread by Sergey Dorofeev | last post: by
10 posts views Thread by Giovanni Bajo | last post: by
4 posts views Thread by OhKyu Yoon | last post: by
2 posts views Thread by brnstrmrs | last post: by
reply views Thread by Ping Zhao | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.