Current location - Training Enrollment Network - Mathematics courses - What is complement?
What is complement?
Complement is the binary representation of a signed number. Complement is a positive number that "replaces negative numbers". With complement, there is no negative number in the computer, and there is no subtraction operation. Therefore, using complement can simplify the algorithm and hardware.

We use B2Tw to represent the complement. Where W stands for the bit length of binary number, and B2T actually means "two's complement". In order to calculate the number actually represented by the complement, we need to multiply the value on each bit by the corresponding weight, and then add it. The weight of each bit (index I, increasing from right to left from 0) is 2i, but the weight of the highest bit is special and needs to be negative, which is -2w- 1.

For the two's complement representation with a bit length of w, the maximum value TMaxw is 2 (w- 1)- 1, the highest bit is 0, and the rest bits are 1. The minimum value TMinw is -2 (w- 1), at which time the highest bit is 1 and the rest bits are all 0. For 4-digit complement, the maximum value TMax4 = B2T4 (), the corresponding value is 2 3-1= 7, and the minimum value is B2T4 (), the corresponding value is-2 3 =-8.

The complement of a positive number is the original code itself, and the complement of a negative number is its complement plus 1. Signed number in computer includes original code, complement and complement. These three representations have two parts: sign bit and digital bit.

The sign bits are all positive 0 and negative 1. In computer systems, numerical values are always represented and stored by complement. The reason is that with the complement, the sign bit and numerical field can be handled uniformly; At the same time, addition and subtraction can also be handled in a unified way.