在一个字节中,我设置了一些位
| 视频 | 音频 | 扬声器 | 麦克风 | 耳机 | LED 使用位来表示
| 1 | 1 | 1 | 3 | 1 | 1
除了麦克风需要 3 个字节以外,其他全部使用 1 个字节,因此可以有 7 种组合方式,留下第一个组合。
现在我设置了比特。
当我像这样阅读时
单独设置的数值可以被找到。 但是多个数值(例如,MicType5、6、7)设置时会出错, 并且显示选项中的第一个。 我做错了什么?
除了麦克风需要 3 个字节以外,其他全部使用 1 个字节,因此可以有 7 种组合方式,留下第一个组合。
#define Video 0x01
#define Audio 0x02
#define Speaker 0x04
#define MicType1 0x08
#define MicType2 0x10
#define MicType3 0x20
#define MicType4 (0x08 | 0x10)
#define MicType5 (0x08 | 0x20)
#define MicType6 (0x10 | 0x20)
#define MicType7 ((0x08 | 0x10) | 0x20)
#define HeadPhone 0x40
#define Led 0x80
现在我设置了比特。
MySpecs[2] |= (1 << 0);
MySpecs[2] |= (1 << 2);
//设置麦克风类型为6
MySpecs[2] |= (1 << 4);
MySpecs[2] |= (1 << 5);
当我像这样阅读时
readCamSpecs()
{
if(data[0] & Video)
printf("device with Video\n");
else
printf("device with no Video\n");
if(data[0] & Audio)
printf("device with Audio\n");
else
printf("device with no Audio\n");
if(data[0] & Mictype7)
printf("device with Mictype7\n");
if(data[0] & Mictype6)
printf("device with Mictype6\n");
}
单独设置的数值可以被找到。 但是多个数值(例如,MicType5、6、7)设置时会出错, 并且显示选项中的第一个。 我做错了什么?