in reply to Re^5: calculating the 3 MSBs from an integer
in thread calculating the 3 MSBs from an integer
Hi Again,
Sorry for implying allegiance to Redmond ;). Back home now and just given it a taz on x86/Linux and I get the same reversed byte order. I guess it is the Intel architecture not the OS. Sadly my Alpha/Linux is in another country and offline so no testing possible there. I will try it on a SPARC at work tomorrow just for fun.
The & 0xff is a bit mask that will only drop through bits from the first (8 bit) byte. If I take it off when I get to 256 my total goes up to 8 (Intel/Linux). As long as your input is only 1 byte then it will not be a problem.
perl -le'print join "\t", $_, (unpack "B*", pack "N", $_), $_ >>5 for +(0..256)' <snip> 254 00000000000000000000000011111110 7 255 00000000000000000000000011111111 7 256 00000000000000000000000100000000 8
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: calculating the 3 MSBs from an integer
by insaniac (Friar) on Feb 18, 2005 at 06:43 UTC |