A pointer to doc that explains what's behind b vs B decoding would be greatly appreciated.
In terms of single bytes, the difference between 'b' & 'B' templates is purely a matter of cosmetics; that is, the same information is being presented differently:
[0] Perl> print unpack 'B8', chr(65);; 01000001 [0] Perl> print unpack 'b8', chr(65);; 10000010
Nothing changed in the hardware or the internal representation of 'A', just order in which the bits are presented to the user.
Where the real difference comes in is when dealing with values greater than one byte:
## spacing and annotation added manually... [0] Perl> print unpack 'b*', "\x12\x34";; 0100 1000 0010 1100 2 1 4 3 [0] Perl> print unpack 'B*', "\x12\x34";; 0001 0010 0011 0100 1 2 3 4
As you can see, not only is the bit-order different, but so is the apparent ordering of the nybbles within the bytes. In part this is due to my using a little-endian hardware. If you are using or have access to a big-endian machine, you'd see different results above, but they would still both be just different ways of viewing the same information.
Again nothing changed in the storage of the values within the memory, the apparent reordering is purely down to the way the bits are displayed.
So, the difference is just an illusion created by the the way you are viewing the bits, and probably not what you should be concentrating on.
Provided you are calculating the correct bit positions for your use of vec in _set_header_field() -- which is a matter of whether you've done your homework correctly -- how you chose to view those bits (ie.with 'b' or 'B') is really down to which makes more sense for you.
In reply to Re: Bit order in bytes
by BrowserUk
in thread Bit order in bytes
by geoffleach
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |