J.C. Wren wrote:
I first saw this on Steve's Cute Code Collection (< http://www.sjbaker.org/steve/software/cute_code.html >). He says he found the 32 bit version in the *nix fortune cookie program. This method is pretty effective for 32 bit numbers, since the look up table version can get a little large :)

For 8 bit numbers, using Steve's shift left/shift right method, I don't think I'd bother with a looping structure. Better just to inline the 16 instructions. The difference in code savings will be minimal and the execution speed won't change much, but it will eliminate managing an extra register for the loop.
gcc decided to unroll the loop into the 16 shifts anyway. C code with loop is nicer to read - i think.

        Georg


   There's a few other tricks on the page that can be handy, also.

   --jc

Steve Underwood wrote:

Hi,

Gosh, I haven't seen that one for years. I think it needs a barrel shifter to work well, though. I'm pretty sure direct shift out and shift in will do better on the MSP430.

Regards,
Steve


Regards,
Steve


Leon Heller wrote:

Here's a clever way to do it that I found via Google:

//
// Reverse the order of bits within a byte.
// Returns: The reversed byte value.
//
BYTE ReverseBits(BYTE b)
{
 BYTE c;
 c  = ((b >>  1) & 0x55) | ((b <<  1) & 0xaa);
 c |= ((b >>  2) & 0x33) | ((b <<  2) & 0xcc);
 c |= ((b >>  4) & 0x0f) | ((b <<  4) & 0xf0);
   return(c);
}

I haven't checked it, though.



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users





-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users





Reply via email to