我在编写程序时注意到,我的许多int
类型变量从未超过 10。我认为因为 anint
最短为 2 个字节(如果计算为 1 char
),所以我应该能够unsigned ints
在一个短整数中存储最大值为 15 的 4,并且我知道我可以使用>>
and单独访问每个字节<<
:
short unsigned int SLWD = 11434;
S is (SLWD >> 12), L is ((SLWD << 4) >> 12),
W is ((SLWD << 8) >> 12), and D is ((SLWD << 8) >> 12)
但是,我不知道如何将它包含在类的函数中,因为任何类型的GetVal()
函数都必须是 type int
,这首先破坏了隔离位的目的。