[issue45782] Bug in struct.pack

2021-11-11 Thread Steven D'Aprano
Steven D'Aprano added the comment: The behaviour is correct. You have tripped over the ASCII representation of bytes. In ASCII, 119 (or in hex, 0x77) is displayed as 'w'. >>> b'\x77\x00\x00\x00' b'w\x00\x00\x00' -- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved

[issue45782] Bug in struct.pack

2021-11-11 Thread Terje Myklebust
New submission from Terje Myklebust : >>> struct.pack("i", 119) b'w\x00\x00\x00' "w" in a binary value? >>> struct.pack("I", 116) b't\x00\x00\x00' "t" in a binary value? -- messages: 406150 nosy: terje.myklebust123

Bug in struct.pack?

2006-01-11 Thread Alex Stapleton
from struct import pack pack(B, 1) '\x01' pack(BB, 0, 1) '\x00\x01' pack(BI, 0, 1) '\x00\x00\x00\x00\x01\x00\x00\x00' calcsize(BI) 8 calcsize(BB) 2 Why does an unsigned char suddenly become 4 bytes long when you include an unsigned int in the format string? It's consistent behaviour

Re: Bug in struct.pack?

2006-01-11 Thread Raymond Hettinger
[Alex Stapleton] from struct import pack pack(B, 1) '\x01' pack(BB, 0, 1) '\x00\x01' pack(BI, 0, 1) '\x00\x00\x00\x00\x01\x00\x00\x00' calcsize(BI) 8 calcsize(BB) 2 Why does an unsigned char suddenly become 4 bytes long when you include an unsigned int in the format string?

Re: Bug in struct.pack?

2006-01-11 Thread Alex Stapleton
Idiot. On 11 Jan 2006, at 10:46, Alex Stapleton wrote: from struct import pack pack(B, 1) '\x01' pack(BB, 0, 1) '\x00\x01' pack(BI, 0, 1) '\x00\x00\x00\x00\x01\x00\x00\x00' calcsize(BI) 8 calcsize(BB) 2 Why does an unsigned char suddenly become 4 bytes long when you include an