I think I have understood this correctly but please put me right if I am barking up the wrong tree

$_[0] & 0xff # A bitmask to gets the last (8 bit) byte from the intege +r. # It has exactly the same result as $_[0] % 256 >> 5 # bitshift the result of the above so all but # the 3 MSB drop off the end.
the return automagically maps this to the decimal for the three remaining bits. Was use integer necessary for this or does it improve efficiency ?

Here is a one liner to dump what is going on

perl -le'print join "\t", $_, (unpack "B*", pack "I*", $_),($_ & 0xFF) + >> 5 for (0..256)'
and some of the output for the interesting regions
0 00000000000000000000000000000000 0 1 00000000000000000000000000000001 0 2 00000000000000000000000000000010 0 . . 30 00000000000000000000000000011110 0 31 00000000000000000000000000011111 0 32 00000000000000000000000000100000 1 33 00000000000000000000000000100001 1 . . 222 00000000000000000000000011011110 6 223 00000000000000000000000011011111 6 224 00000000000000000000000011100000 7 225 00000000000000000000000011100001 7 . . 255 00000000000000000000000011111111 7 256 00000000000000000000000100000000 0

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re^2: calculating the 3 MSBs from an integer by Random_Walk
in thread calculating the 3 MSBs from an integer by insaniac

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.