in reply to Re^4: calculating the 3 MSBs from an integer
in thread calculating the 3 MSBs from an integer

that was it! And I'm using Linux btw, it's been ages since I used MS ;-)
but i still don't understand why the & 0xFF is required... without it, it seems to work as well
--
to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re^6: calculating the 3 MSBs from an integer
by Random_Walk (Prior) on Feb 17, 2005 at 22:20 UTC

    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.

    Pereant, qui ante nos nostra dixerunt!
      ah thanks! now i understand...
      and at work, i also have a (ultra)sparc(5) with debian linux on it ;-)
      --
      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame