【发布时间】:2015-01-30 08:14:05
【问题描述】:
我有许多 int 类型。它位于 [0,255] 内。即,包括 8 位。我需要经常检查说:
2(int) = 00000010(二进制)
1. The bit 6 and bit 7 must be equal to 0 and 1 respectively. And I check it like this:
if ((!(informationOctet_ & (1 << 6))) && (informationOctet_ & (1 << 7)))
{
...
}
但它的可读性不是很高,是否有可能——做一些“漂亮”的事情? 我不能使用 std::bitset,我的脑袋说这是浪费资源,你不能没有它。
【问题讨论】:
-
(x & 0xC0) == 0x80(即通常的方式)不够好吗?
标签: c++11 int bit-manipulation bit