geoffleach has asked for the
wisdom of the Perl Monks concerning the following question:

I am (for my sins) the maintainer of Audio::TagLib. There, I said it. My question arises out of constructing code that creates a 32-bit header for MPEG files. The header consists of bit fields of various widths.

This question concerns the ordering of bits in a 8-bit byte, packed into an integer. If I number the bits 7..0, the assignment results in a value when unpacked with 'b*' gives me the expected result: 11110010, with bit #7 on the left. The TagLib C++ library with which I communicate expects the field to look like this: 01001111, which is what one gets when unpacking with B*.

A pointer to doc that explains what's behind b vs B decoding would be greatly appreciated.

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.

It has a lot to do with human nomenclature ... do they number the bits from left-to-right (0=MSB), or from right-to-left? Then, entirely separately from this, do they store a multi-byte number high-byte-first or low-byte-first? Finally, how does your programming-tool of choice do it? There are no "right" answers. When you are doing bit-twiddling, you have to think of all these things, and it is highly machine-specific. Documentation and project designs need to explicitly spell-out all of these things, right there on the front page, and it should also be summarized in documentation within the source code.

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other