Representation of numbers in a computer

Source: Internet
Author: User

In real life, we usually use 10 binary to represent our numbers, whereas in computers we use "0" and "1" to represent the binary of numbers.

If we use a byte to store a number, then this number may be stored in the computer in this way: 00010011. The leftmost 0 bits are used in signed numbers to denote a sign, 0 for a plus, 1 for a minus, so it's called the sign bit, and the other digits are used to denote a specific number, so it's called a value bit.

00010011 if it is used to represent a signed integer, then it represents a number of +19. +19 is called the true Value, 00010011 is used to represent in the computer, so called machine number .

The number of machines in the computer in the representation of three kinds, the original code, anti-code and complement.

  The representation of the original code:

    The left is the sign bit with a positive number of 0 and a negative number of 1. Other bits represent numeric values

"+10" Original code = 00001010

"-10" Original code = 10001010

"+0" Original code = 00000000

"-0" Original code = 10000000

  The expression of the inverse code:

The inverse of a positive number is the same as the original code, and the inverse of the negative number is reversed by the original code except for the rest of the sign bit (i.e. 0 table 0)

"+10" anti-code = 00001010

"-10" anti-code = 11110101

"+0" anti-code = 00000000

"-0" anti-code = 11111111

  The expression of complement:

The complement of positive numbers is the same as the original code, and the complement of negative numbers is obtained by adding 1 to the original code.

"+10" complement = 00001010

"-10" complement = "10" anti-code + 1 = 11110101 + 1 = 11110110

"+0" complement = 00000000

"-0" complement = "0" anti-code + 1 = 11111111 + 1 = "1" 00000000 (mod (256))

The meaning of complement: the complement is actually a kind of modulo operation, take the clock as an example, the clock is a circle of 12 hours, that is, the clock module is 12. If the current moment is 3 o'clock, it becomes 15 points after 12 hours, and 15 after modulo 12, is still 3 points. For example, turn the 3-point clock down by one hours, which is the same as 2 points, and adjust the hour-hour forward by 11 hours. So use the same results as 3-1 and (3+11) mod (12). The use of complement in machine code is mainly to replace subtraction by adding the meta-computation. The adder of the CPU is simple and efficient, so there is no need to implement the subtraction device specifically.

In 8-bit words, our modulo is 2 of the 8-time square, or 256. For example:

Direct subtraction: 01000000 (64)-00001010 (10) = 00110110 (54)

Replace subtraction with complement: 01000000 (64) + (11110110) (246) = 00110110 (54)

The results of the two operations are the same.

Representation of numbers in a computer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.