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.

  1. 'b' produces lsb -> msb; left to right.
  2. 'B' produces msb -> lsb; left to right.

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.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Bit order in bytes by BrowserUk
in thread Bit order in bytes by geoffleach

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.