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 On Tue, Sep 3, 2019 at 6:25 PM ToddAndMargo via perl6-users < perl6-us...@perl.org> wrote: > On 9/3/19 5:52 PM, yary wrote: > > I'm puzzled what you really want, what the end goal is. > > > > For looking at different representations of the same item, "pack" and > > "unpack" are useful. I've only used the perl5 versions of those, for p6 > > it is "experimental". Different machines will represent the same real > > differently, and if I recall correctly not even IEEE standards exactly > > specify representation of float and it can vary by compiler too. > > > > Perl 6's native experimental pack/unpack don't support real, nor does > > the P5pack module, so reverting to perl5... big/little b/h is binary or > > hex in big/little-endian order. With quoting that should work in either > > Win or Unix > > > > $ perl -E "say unpack 'b*',pack 'f', 12.34" > > 00100101000011101010001010000010 > > $ perl -E "say unpack 'B*',pack 'f', 12.34" > > 10100100011100000100010101000001 > > $ perl -E "say unpack 'h*',pack 'f', 12.34" > > 4a075414 > > $ perl -E "say unpack 'H*',pack 'f', 12.34" > > a4704541 > > > > > Thank you! > > What is the difference between b*, B*, h*, and H* ? > > > $ perl -E "say unpack 'b*',pack 'f', 11.00" > 00000000000000000000110010000010 > > $ perl -E "say unpack 'b*',pack 'f', 11.01" > 01101111000101000000110010000010 > > $ perl -E "say unpack 'b*',pack 'f', 10.999999999" > 00000000000000000000110010000010 >