如果你使用位运算符(&
、|
等)来比较两个不同大小的位字段会发生什么?
例如,比较 0 1 1 0
和 0 0 1 0 0 0 0 1
:
0 1 1 0 0 0 0 0 The smaller one is extended with zeros and pushed to the
0 0 1 0 0 0 0 1 most-significant side.
或者......
0 0 0 0 0 1 1 0 The smaller one is extended with zeros and pushed to the
0 0 1 0 0 0 0 1 least-significant side.
或者...
0 1 1 0 The longer one is truncated from its least-significant side,
0 0 1 0 keeping its most significant side.
或者...
0 1 1 0 The longer one is truncated from its most-significant side,
0 0 0 1 keeping its least-significant side.
C++
标签,因为我不确定这是否因语言而异。 - Maxpm