Representation of numbers in computer original code one's complement complement

  Numbers in computers are divided into unsigned numbers and signed numbers. All bits of the binary bit corresponding to an unsigned number are used to represent numbers. An unsigned number is a positive number, and its representation in memory is its corresponding binary. It is quite troublesome to represent signed numbers in memory, because the highest bit in the corresponding binary bit is used to represent the positive and negative of the number, and not all bits can be used to represent the number.

  Unsigned numbers, because all binary bits can be used to represent numbers, so the range interval that can represent unsigned numbers for single-byte binary bits is [0,255], a total of 256 numbers. In computer memory, it is logical to directly use the binary corresponding to the unsigned number to represent the unsigned number.

  Signed numbers, because the highest bit is used to represent the positive and negative of the number, all the corresponding binary bits cannot be used to represent the number. For a single byte, the binary bits 1111 1111 represent the minimum number -127, and the binary bits 0111 1111 represent the maximum number 127. Therefore, for a single-byte binary bit, the range interval that can represent a signed number is [-127,127], a total of 255 numbers, of which binary bits 1000 0000 represent negative 0, and binary bits 0000 0000 represent positive 0. It is not logical to directly represent these numbers in memory with the binary corresponding to the signed number, because the unsigned number must represent 256, and the signed number must also represent 256 numbers. If the negative 0 represented by 1000 0000 is divided into -128, it is just fine, and the range of signed numbers is changed to [-128, 127], so that it can correspond to the range of unsigned numbers. However, when the computer processes numbers, -127+(-1)=-128, which is represented in memory as 1111 1111 + 1000 0001 = 1 0000 0000, and after a single-character overflow becomes 0000 0000 means 0, not 1000 000 -128; Because computers only deal with regular computers, this method of directly using binary to represent signed numbers in memory is obviously not applicable, which will bring difficulties to hardware CPU design.

  The computer has the original code, the inverse code and the complement code. The manipulation of these bits is to solve the way that signed numbers are represented in memory.

  Unsigned numbers can directly use their corresponding binary to represent the form in memory, and they are all positive numbers. Therefore, it is stipulated that the original code of the positive number, the inverse code and the complement code are the binary itself.

  Signed numbers cannot directly use their corresponding binary to represent the form in memory, so we need to refer to the relationship between the original code, the inverse code and the complement code to solve this problem. The original code corresponding to -127 is its binary 1111 1111, the inverse code is 1000 0000, and the complement code is 1000 0001; the original code of 127 positive number, the inverse code and the complement code are both its binary itself, which is 0111 1111; assign 0 to positive When counting, the original code, the complement code and the complement code are all its binary itself 0000 0000; when 0 is assigned to a negative number, the original code is 1000 0000, the complement code is 1111 1111, and the complement code is 1 0000 0000; because for mathematical logic, there is no positive code. The division between 0 and negative 0, 0 is neither positive nor negative, so the positive 0 represented by 0000 0000 is defined as 0, and the negative 0 represented by 1000 0000 is represented as -128. This also reduces the difficulty for designing CPUs, because there is no subtraction in the computer, and subtraction is represented by adding a negative number to a number. For example -127+(-1) = -128 memory's complement + negative 1's complement memory = 1000 0001 + 1111 1111 = 1 0000 0000 = negative 0's complement = specified -128. This can solve the difficulties in hardware CPU design; for example, 127-1=127 memory complement + negative 1 memory complement = 0111 1111 + 1111 1111 = 1 0111 1110 = 0111 1110 (remove the highest bit) = 126.

  If you want to understand the above content, you must first review the binary mathematical operations, and have a proper understanding of the unit byte of memory.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325077102&siteId=291194637