猿问

按位运算符的实际用例

以下按位运算符的一些实际用例是什么?

  • XOR

  • 要么


largeQ
浏览 662回答 3
3回答

ABOUTYOU

这很奇怪吗?(value & 0x1) > 0它可以被两个(偶数)整除吗?(value & 0x1) == 0

喵喔喔

这里有一些常见的习惯用法处理存储为单个位的标志。enum CDRIndicators {&nbsp; Local = 1 << 0,&nbsp; External = 1 << 1,&nbsp; CallerIDMissing = 1 << 2,&nbsp; Chargeable = 1 << 3};unsigned int flags = 0;设置Chargeable标志:flags |= Chargeable;清除CallerIDMissing标志:flags &= ~CallerIDMissing;测试是否设置了CallerIDMissing和Chargeable:if((flags & (CallerIDMissing | Chargeable )) == (CallerIDMissing | Chargeable)) {}
随时随地看视频慕课网APP
我要回答