On 2019-12-02 09:55:16 -0800, Rob Gaddi wrote:
> The struct situation is, as you said, a bit different.  I believe that with
> the default native alignment @, you're seeing 4-byte data padded to an
> 8-byte alignment, not 8-byte data.

Nope. That's really an 8 byte long:

    Python 3.7.3 (default, Apr  3 2019, 05:39:12)
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import struct

    >>> struct.pack('L', 0x0807060504030201)
    b'\x01\x02\x03\x04\x05\x06\x07\x08'

All 8 bytes are serialized. Trying to serialize 9 bytes (actually only 68
non-zero bits) fails:

    >>> struct.pack('L', 0x090807060504030201)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    struct.error: argument out of range

And when you use the "standard size", 8 bytes are also too much:

    >>> struct.pack('=L', 0x0807060504030201)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    struct.error: 'L' format requires 0 <= number <= 4294967295

But 4 bytes are ok:
    >>> struct.pack('=L', 0x04030201)
    b'\x01\x02\x03\x04'


        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | h...@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment: signature.asc
Description: PGP signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to