送分!如何输出或者得到位数据?
- C/C++ code
typedef struct myStruct{ int OneBit :1;}Bit_t;int main(){ Bit_t stVar = 0; int arr[2] = {0x40,0x11}; stVar.OneBit = arr[0] & 0x40;}
怎么输出stVar.OneBit的值??我用printf()为0的。
[解决办法]
确实是个0啊,1比特的数据表达范围就0和1,你0x40&0x40=0x40,最低位是0,赋给了OneBit
[解决办法]
标准设备不能输出结果吗?
[解决办法]
你这样本来就应该得到0的啊。
[解决办法]
stVar.OneBit =(arr[0] == 0x40 ? 1 : 0);
[解决办法]
- C/C++ code
typedef struct myStruct { unsigned int OneBit :1; }Bit_t; Bit_t stVar; stVar.OneBit = 0; printf("%d\n",stVar.OneBit); stVar.OneBit = 1; printf("%d\n",stVar.OneBit);
[解决办法]
01000000
00010001 按位与
00000000 则stVar.OneBit为0