### How do you calculate the range of 8-bit binary original complement inverse code?

The range of 8-bit binary original code:-127～+127.

The range of 8-bit binary inverse code:-127～+127.

The range of 8-bit binary complement code:-128～+127.

The inverse code is a kind of numerical storage, which is mostly used in the system environment setting, such as the linux platform. The inverse code principle is used to set umask, the default permissions for directories and files. Within computers, there are 3 ways to represent fixed point numbers: original, inverse and complement.

The original code is the simplest form of computer machine number, the numerical value of the bit is the absolute value of the true value, the sign bit “0” when the number is positive, the sign bit “1” when the number is negative, the original code is also known as the absolute value of the sign. In order to facilitate the distinction between integers and decimals, the integer sign bit and the numerical value of the bits separated by “,”, the decimal sign bit and the numerical value of the bits separated by “.” between the sign and value places of decimals.

### What is the range of numbers that can be represented by the original, complement and inverse codes of eight- and sixteen-bit binary numbers

8-bit original code represents the range: -127 to -0, +0 to +127

8-bit inverse code represents the range: -127 to -0, +0 to +127

8-bit complement range: -128 to 0 to +127

————–

16-bit original code range: -32767 to -0, +0 to +32767

16-bit inverse code range: -32767 to -0, +0 to +32767

16-bit complement code range: -32768 to 0 to +32767

Because of the original code and inverse code coding rules, resulting in +0 and -0 such as “strange values”, while the complementary code does not have this phenomenon. This is one of the reasons why complementary codes are widely used in computers!

### Conversion and range of representation of prime, inverse and complement

Numbers are stored in binary in machines, and signed numbers have three representations: prime, inverse and complement. In all three representations, the highest bit represents the sign bit, 1-negative, 0-positive.

1.Original code

The original code of a number is the number directly converted to binary, the first bit is the sign bit.

2. Inverse code

The inverse code of a positive number is itself; the inverse code of a negative number is the original code except for the sign bit which does not move, all the other bits are inverted by bit.

3. Complement

The complement of a positive number is itself; the complement of a negative number is the inverse plus one (including the sign bit).

Therefore, the original and negative complements of positive numbers are equal, and the original and negative complements of negative numbers are converted to each other.

Example:

The computer stores and calculates 8-5, because the CPU has only adders, so it has to convert 8-5 to 8+(-5) to calculate.

(+8)

Original code of 8: 00001000

Inverse code of 8: 00001000

The complement of 8: 00001000

(-5)

-Original code of >-5: 10000101

The inverse code of -5: 11111010

The complement of -5: 11111011

8-5=8+(-5)=00001000+11111011=0000000011

<

0000000011 sign bit is 0, then represents a positive number, the original backward complement are the same, converted to decimal is 3.

So, the data in the computer in the form of complementary code to represent and store, the complement of the code is also more convenient to calculate.

Two, the original code, the inverse code and the complement of the representation of the range

Generally, the computer word length of 32 bits, that is, 32-bit binary representation of the number:

Original code: – [2 ^ (n-1)-1] ~ 2 ^ (n-1)-1

Inverse code: – [2 ^ (n-1 )-1]~2^(n-1)-1

Complement: -2^(n-1)~2^(n-1)-1

### In the original code, complement, inverse code, who has the largest range of representation

8-bit binary machine code as an example:

.

Original code range:11111111b～01111111b

True value range:-1111111b～+1111111b,i.e.-127d～+127d

.

Inverse code range:10000000b～01111111b

True value range:-1111111b～+1111111b,i.e.-127d～+127d

.

Complement range: 10000000b to 01111111b

Corresponding true value range:-10000000b to +1111111b,i.e. -128d to +127d

.

In this regard, it can be seen that the complementary code represents the largest range of values.

### The range of the original inverse complement

If a byte is used to hold the signed numbers, then the eight bits of the original code, represent a range of -127—-+127

The eight bits of the inverse code represent a range of -127—–+127

The eight bits of the complement code represent a range of -128——+127

### How to calculate the range of decimal numbers that can be represented by N-bit binary number original, inverse, and complement

The range of decimal numbers that can be represented by N-bit binary number original, inverse, and complement is -2^(N-1)-1~+2^(N-1)-1.

The range of decimal numbers that can be represented by N-bit binary number complement is -2^(N-1)~+2^(N-1)-1.

Conversion of binary number to decimal number uses “weighted addition” method.

Binary numbers are converted to decimal numbers using the “weighted sum” method, in which the binary numbers are first written as an expansion of the weighted coefficients, and then summed according to the rules of decimal addition.

The original code states: the sign bit and numerical value of the signed number, the sign bit of the positive number with “0”, the sign bit of the negative number with “1”, the numerical value of the part of the binary form of expression. So the range of decimal numbers that can be expressed by the original N-bit binary number is -2^(N-1)-1~+2^(N-1)-1.

The inverse representation states that the inverse of a positive number is the same as the original number, and the inverse of a negative number is the inverse of the original number except for the sign bit.

The inverse code of an N-bit binary number can be expressed in the range of -2^(N-1)-1~+2^(N-1)-1.

The complement code specifies that the complement of a positive number is the same as that of the original code, while the complement of a negative number is the inverse of all the bits except the sign bit of the original code, and then 1 is added to the last bit.

The complement of an N-bit binary number can be expressed in the range of -2^(N-1)-1~+2^(N-1).

The complement code specifies that the complement of a positive number is the same as the original code, while the complement of a negative number is the inverse of all the bits except the sign bit, and then 1 is added to the last bit. 1)~+2^(N-1)-1.

Expanded information:

The original code is the simplest way to encode signed numbers, easy to input and output, but as a code for addition and subtraction operations are more complex. In computer systems, values are always represented and stored in complementary codes. The reason is that, using the complementary code, can be the sign bit and numerical domain unified treatment; at the same time, addition and subtraction can also be unified treatment.

In computers, it is very easy to use the characteristics of electronic devices to realize the complementary code and the true value, the original code between each other. The complementary code represents the unification of the sign bit and the numerical bit, so that the sign bit can be directly involved in the operation together with the numerical bit, which also provides a great convenience for the later design of the multiplier divider and other arithmetic devices.