//二进制逆序 by MoreWindows( http://blog.csdn.net/MoreWindows )
#include <stdio.h>
//二进制打印函数
template <class T>
void PrintfBinary(T a)
{
int i;
for (i = sizeof(a) * - ; i >= ; --i)
{
if ((a >> i) & )
putchar('');
else
putchar('');
if (i == )
putchar(' ');
}
putchar('\n');
}
int main()
{
printf("二进制逆序 \n\n");
printf("逆序前: ");
unsigned short a = 0x1FFF;
PrintfBinary(a);
a = ((a & 0xAAAA) >> ) | ((a & 0x5555) << );
a = ((a & 0xCCCC) >> ) | ((a & 0x3333) << );
a = ((a & 0xF0F0) >> ) | ((a & 0x0F0F) << );
a = ((a & 0xFF00) >> ) | ((a & 0x00FF) << );
printf("逆序后: ");
PrintfBinary(a);
printf("false ");
}
转自:http://blog.csdn.net/MoreWindows