From: Mark Day Date: 2007-06-20T03:38:37+09:00 Subject: Re: Unpacking signed shorts and integers with specified endianness On Jun 19, 2007, at 11:19 AM, Daniel Berger wrote: >> 1) I see "l" (lowercase L) which is 4 bytes treated as a signed >> integer...but in 'native' endian order. Does String.unpack not >> provide >> a way to unpack a 4-byte signed integer with a specified endianness? >> >> 2) I see "s" which is 2 bytes treated as a signed integer...but in >> 'native' endian order. Does String.unpack not provide a way to unpack >> a 2-byte signed integer with a specified endianness? > > See the 'N', 'n', 'V' and 'v' directives. There are equivalent > directives for floats as well - 'E', 'e', 'G' and 'g'. Those handle endianness, but not signed values. I suppose you could unpack as unsigned, then manually test for the sign bit being set and correct the value. Even uglier, you could unpack as unsigned with desired endianness, repack as unsigned in native order, then unpack as signed in native order. -Mark