Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 17:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found