Only 0 and 1 are present in the computer, and only positive integers and 0 are expressed under such conditions.
Word Length: Computer CPU performance index, refers to the CPU can be processed at a time, the number of bits processed.
Fixed length: When the computer represents the information, the number of bits, the number of bits, is called the constant length.
With the n-bit fixed length constraint, the computer represents a range of values of [0,2^n]
Under the N-bit length, the following equation exists
2^n = 0
Original code:
To be able to represent negative numbers, introduce the original code
The original code on the basis of n-bit length, the introduction of the highest bit of positive and negative, where 1 is negative, 0 is a positive number.
The value range for n-bit Primitives is ( -2^ (n-1), 2^ (n-1))
When n is 8 o'clock, for [ -127,+127]
There is no original code in the computer
Complement:
There are two major operations in the computer: logical and arithmetic operations
Logical operations: Or, with, non, XOR, or
A B a&&b a| | B a^b
0 1 0) 1 1
1 1 1) 1 0
1 0 0) 1 1
1 1 1) 1 0
Arithmetic operations:
A B A+b
0 1 01
1 1 10
1 0 01
0 1 01
Summary: Rounding equals a&&b
Standard equals a^b
Due to the existence of borrow in the subtraction circuit, it cannot be implemented with simple circuit, so the complement is introduced.
The definition of complement:
If you mean positive, the original code equals the complement
If the negative, then on the basis of the original code, except the sign bit, you take the reverse and then the last plus 1
In the fixed length of 8, 8 of the original code:
1000 1000
So according to the definition of its complement:
1111 1000
(x + y) complement = X's complement + Y's complement
Range of N-complement representations: [ -2^ (N-1), 2^ (n-1))
The n-bit complement represents the reason for a single number more than the N-bit original code:
When the original code means 0, 0000 0000 means 0 1000 0000 means 0,
The two original codes correspond to the same complement, so the original code is one number less than the complement
There is a problem with the complement
For a 8-bit length, its complement range [-127,127]
127+1 = =-127
As above, the size of the complement is range and interconnected.
int i;
for (i = 1; i > 0; i++)
;//not an infinite loop function
Original code and complement