#define GET_BIT(VALUE, OFFSET) (((VALUE)>>(OFFSET)) & 1)
#define SET_BIT(VALUE, OFFSET) (((VALUE) & 1)<<(OFFSET))
测试程序
int main()
{
int pt = 0x05;
unsigned char t[32];
unsigned int v = 0;
for (size_t i = 0; i < 32; i++) {
t[i] = 1;
}
t[31] = 1;
t[0] = 1;//1
t[1] = 1;//2
t[2] = 0;//4
t[3] = 1;//8
for (size_t i = 0; i < 32; i++) {
v |= SET_BIT(t[i], i);
}
printf("v:%u\n", v);
for (size_t i = 0; i < 18; i++) {
if (GET_BIT(pt, i))
{
printf("%d\n", i);
}
}
getchar();
return 0;
}