可以说我有一个位掩码如何通过位掩码存储和检索3位数字?
enum ExampleMask
{
Attribute1 = 1 << 1,
Attribute2 = 1 << 2,
...
Attribute27 = 1 << 27
}
所以我已经用我的32个可用位27。
我现在想要除了使用位掩码的标志之外还能够存储和检索3位无符号整数。
例如:
// Storing values
int mask = Attribute2 | Attribute6 | Attribute18; // Saving some attributes
int mask |= ???? // How to save the number 8?
// Retrieving values
if(mask & Attribute2) do something...;
if(mask & Attribute6) do something...;
int storedValue = ???? // How to retrieve the 8?
基本上我想在我的位掩码保留3位保存在那里
0-8之间的数字。感谢您抽出时间来阅读和帮助。
'int mask = 9'? –
我需要能够正常存储标志,除了保存9 – xNidhogg
9需要4位 –