struct.unpack on 64-bit platforms

N

Nadav Samet

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
 
G

Georg Brandl

Nadav said:
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
 
J

Jorgen Grahn

On 22 Jun 2006 09:30:26 -0700 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top