//输入一个十六进制的数,然后按位输出2进制形式
#include <stdio.h>
#include <Windows.h>
void showbit(int Num)
{
typedef unsigned char uc;
uc* pbite = (uc*)&Num;
for (int j=0;j<4;j++)
{
uc cBit = *pbite;
for (int i=0;i<8;i++)
{
//putchat(0x80&cBit ? '1':'0');
if (0x80 & cBit)
putchar('1');//printf("%c",'0');
else
putchar('0');
cBit = cBit << 1;//cBit <<= 1;
}
putchar(' ');
pbite++;
system("pause");
}
}
int main()
{
int i = 0x61626364;
showbit(i);
return 0;
}
转载于:https://my.oschina.net/HappyTeemo/blog/1558520