Forcing endianness when packing signed values

Greetings,

Why is it possible to pack unsigned short and int values in
little-endian byte order (using the ‘v’ and ‘V’ formats) and not signed
values ?

[ 42].pack(“v”).unpack(“v”)[0] # => 42
[-42].pack(“v”).unpack(“v”)[0] # => 65494

So I have to use stuff like

[-42].pack(“v”).unpack(“v”)[0] - 65536 # => -42

Not a showstopper, but not so nice either… :slight_smile:

···


Luc Heinrich - lucsky@mac.com