I think I have understood this correctly but please put me right if I am barking up the wrong tree
the return automagically maps this to the decimal for the three remaining bits. Was use integer necessary for this or does it improve efficiency ?$_[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.
Here is a one liner to dump what is going on
and some of the output for the interesting regionsperl -le'print join "\t", $_, (unpack "B*", pack "I*", $_),($_ & 0xFF) + >> 5 for (0..256)'
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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |