#include <stdio.h>
typedef unsigned int UINT_32;
typedef unsigned char UINT_8;
UINT_8 GetBit(UINT_32 number,UINT_32 index)
{
if(index < 0 || index > 31)
return 0xff; //如果传入参数有问题,则返回0xff,表示异常
return (number>>index)&1UL;
}
int main(void)
{
int n = 0x9521;
int i = 0;
for(i = 31; i >= 0; i--)
{
printf("%d",GetBit(n,i));
if(i%4 == 0)
putchar(' ');
}
putchar('\n');
return 0;
}
个人代码,仅供参考!