On 9/3/19 10:24 PM, yary wrote:
b vs B changes the order to show the bits within each byte
h vs H changes the order to show the nybbles within each byte

I'm not so good at explaining, and I remember you saying you're not so good with docs such as https://en.wikipedia.org/wiki/Endianness - so I'll give you some more pack/unpack examples to play with, and you can make examples to show yourself what they do

- using the same 'f' to unpack is a round-trip, and lets you know how things are being rounded
$ perl -E "say unpack 'f',pack 'f', 12.34"
12.3400001525879
$ perl -E "say unpack 'f',pack 'f', 10.999999999"
11
- 'f' is a float (4 bytes on my machine) , 'd' is a double
perl -E "say unpack 'd',pack 'd', 12.34"
12.34 # more precise rounding than float
$ perl -E "say unpack 'h*',pack 'd', 12.34"
ea741ea741ea8204 # more bytes than float

Ints are easier to understand, you can use C for 1-byte ints
$ perl -E "say unpack 'H*', pack 'C', 13"
0d
$ perl -E "say unpack 'h*', pack 'C', 13"
d0
$ perl -E "say unpack 'B*', pack 'C', 13"
00001101
$ perl -E "say unpack 'b*', pack 'C', 13"
10110000

-y


Thank you!

Reply via email to