Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 尝试测试字符值中是否设置了位_Objective C_Bit Manipulation - Fatal编程技术网

Objective c 尝试测试字符值中是否设置了位

Objective c 尝试测试字符值中是否设置了位,objective-c,bit-manipulation,Objective C,Bit Manipulation,如果使用getBytes:range从NSData对象中提取字符数组: 我想测试是否设置了特定位。我会假设我会用一个按位的和,但它似乎不适合我 我有以下资料: unsigned char firstBytes[3]; [data getBytes:&firstBytes range:range]; int bitIsSet = firstBytes[0] & 00100000; if (bitIsSet) { // Do Something } firstBytes[0

如果使用getBytes:range从NSData对象中提取字符数组:

我想测试是否设置了特定位。我会假设我会用一个按位的和,但它似乎不适合我

我有以下资料:

unsigned char firstBytes[3];
[data getBytes:&firstBytes range:range];

int bitIsSet = firstBytes[0] & 00100000;

if (bitIsSet) {
  // Do Something
}

firstBytes[0]的值为48(或作为ASCII字符的“0”)。然而,bitIsSet似乎总是0。我想我只是在做一些愚蠢的事情,我是一个新手,所以我的逻辑可能是错误的。

如果你在一个数字前加上一个
0
,你会说它是用八进制表示的。
00100000
在十进制表示法中实际上是指
32768
,在二进制表示法中是指
1000000000000

试一试


谢谢你。我知道这很简单。成功了!
int bitIsSet = firstBytes[0] & 32;
int bitIsSet = firstBytes[0] & 0x20;