【我解C语言面试题系列】005 按位反转字符问题
按位反转字符问题
Write a C function to swap the bits of a unsigned char so that its bits become the mirror image of the char. MSBs become its LSBs, e.g. 01111000 binary should become 00011110 binary.
方法一:(最最容易想到的办法)
unsigned char ReverseBitsInChar00(unsigned char Num)
{
unsigned char ret = 0;
int i;
for(i=0;i<8;i++)
{
ret <<= 1;
ret |= Num & 1;