编程中的位运算、字符串、数组及其他基础操作
1. 位运算
1.1 按位与(Bitwise AND)
按位与操作使用 & 运算符,它会对两个操作数的对应位进行与运算。以下是示例代码:
unsigned char d = a & b;
printf("Hex: %x & %x = %x\n", a, b, d);
printf("Decimal: %d & %d = %d\n", a, b, d);
return 0;
运行代码后,会输出按位与的结果。例如:
Hex: 3c & a9 = 28
Decimal: 60 & 169 = 40
在 Objective-C 中,按位与常用于检查某个位或标志是否被设置。例如,检查 NSDataDetector 是否设置为查找电话号码:
if ([currentDetector checkingTypes] & NSTextCheckingTypePhoneNumber) {
NSLog(@"This one is looking for phone numbers");
}
超级会员免费看
订阅专栏 解锁全文
1089

被折叠的 条评论
为什么被折叠?



