如何从 Objective C 中的 NSData 十六进制值中按索引获取位值

How to get the Bit value by index from NSData Hex value in Objective C

我有 NSDataHex

<80140142 0073ffff ffff04ff>

我可以通过索引

得到Byte

NSData *commandIDData = [mqttResponseData subdataWithRange:NSMakeRange(3,1)]; <42> // 66

如何通过索引获取 Bit 值?

0100 0010

例如

index[0]=0 index[1]=1
index[2]=0
index[4]=0

NSData *statusData = [mqttResponseData subdataWithRange:NSMakeRange(3,1)];

const unsigned char *statusByte = [statusData bytes];//Hex<4F>/Decimal-79/Binary-01001111

for (int i = 0 ; i < 8; i++) {
    bool chanelValue = [[NSNumber numberWithChar:(*statusByte >> i) & 0x01] boolValue];//i = 0 right most bit
    NSLog(@"chanelValue %d: %d",i+1,chanelValue);//1 1 1 1 0 0 1 0
}