ES.101: Use unsigned types for bit manipulation
ES.101:使用无符号类型进行位操作
Reason(原因)
Unsigned types support bit manipulation without surprises from sign bits.
无符号类型支持不受符号位干扰的位操作。
unsigned char x = 0b1010'1010;
unsigned char y = ~x; // y == 0b0101'0101;
Unsigned types can also be useful for modulo arithmetic. However, if you want modulo arithmetic add comments as necessary noting the reliance on wraparound behavior, as such code can be surprising for many programmers.
无符号类型在模运算时也很有用。然而,如果你想使用模运算的话,增加必要的注释说明结果会依赖环绕行为,因为这样的代码会让很多程序员感到迷惑。
Enforcement(实施建议)
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es101-use-unsigned-types-for-bit-manipulation