先贴上补码的定义:Two’s Complement
其次是反码的定义:One’s Complement
======以上链接可能需要科学上网,若不能打开,可先不看,我将在下面用原文给出======
One’s Complement:
The ones’ complement of a binary number is the value obtained by
inverting all the bits in the binary representation of the number
(swapping 0s and 1s). This mathematical operation is primarily of
interest in computer science, where it has varying effects depending
on how a specific computer represents numbers.
//上面这段话指出反码是将所有bit位全部取反(cpu并不知道数值有无符号,要配合标志位识别符号位,下面英文指出计算机采用的更巧妙的补码操作算法,可不看)。
A ones’ complement system or ones’ complement arithmetic is a system
in which negative numbers are represented by the inverse of the binary
representations of their corresponding positive numbers. In such a
system, a number is negated (converted from positive to negative or
vice versa) by computing its ones’ complement. An N-bit ones’
complement numeral system can only represent integers in the range
−(2N−1−1) to 2N−1−1 while two’s complement can express −2N−1 to
2N−1−1. It is one of three common representations for negative
integers in microprocessors, along with two’s complement and
sign-magnitude.The ones’ complement binary numeral system is characterized by the bit
complement of any integer value being the