# Number representation in the computer

Source: Internet
Author: User

(1) binary
The information processed by the electronic computer is represented by only "0" and "1", or is encoded with this number. This digital system is called binary. To understand a computer, you must first understand the expression of numbers in the computer.
The following four rules can be used to describe any data generation:
Base Rule; carry rule; bit weight rule; operation rule. This distinguishes the numbers represented by different numbers. Generally, the numbers in parentheses are represented by another subscript on the right. The decimal number is represented by d, and the binary number is represented by B, the hexadecimal number is represented by H.
Binary
The following rules are used to describe the binary number: "0" and "1". The base number is 2, and the maximum number is 1, each user's right is a power of 2. For example, the weights of (0101101010) members are 27, 26, 25, 24, 23, 22, 21, and 20 in sequence.
The arithmetic rule of the binary number. It is the same as the decimal number except the input and borrow bits.
0 + 0 = 0 1 + 0 = 1
0 + 1 = 1 1 + 1 = 10
■ Binary subtraction rules
0-0 = 0 0-1 = 1-borrow
1-0 = 1 1-1 = 0
■ Binary multiplication rules
0x0 = 0 1x0 = 0
0x1 = 0 1x1 = 1
Example 4: Binary Number 11110 101 = 110
110
101) 11110
-101

101
-101

00
■ Binary only has two numbers: "0" and "1", which are easy to represent. Voltage height and low, transistor cutoff and saturation, magnetic material magnetization can be expressed as "0" and "1.
■ Each bit of the binary number is only in the 0 and 1 states, which can be expressed by only two devices. Therefore, the binary number saves the device. Because the status is simple, it has strong anti-interference and high reliability.
The main disadvantage of binary is that digits are too long to read and write. For this reason, octal and hexadecimal are commonly abbreviated as binary. To adapt to people's habits, binary numbers are usually used in the computer, and the input and output are in decimal number. The computer converts binary numbers to decimal numbers.
0 + 1 = 1 1 + 1 = 10

(2) Conversion between hexadecimal and Digital Systems
There are sixteen numbers in hexadecimal notation: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, where the A-F represents a number of 10-15, the base number is 16, and the maximum number is 15, which is represented by F. Each digit contains 16 digits.
The hexadecimal number is an abbreviated form of binary number. The four-digit binary number has sixteen combinations, corresponding to the decimal number 0-15. The binary number is converted to the hexadecimal number. the decimal point starts from the decimal point and is left segmented by four bits. When the maximum and low bits are less than four bits, add 0 to supplement the four bits, then use an equivalent hexadecimal number for replacement. In turn, the way to convert a hexadecimal value to a binary value is to write each hexadecimal number in four bits. The leftmost or rightmost can be omitted.
Converts a decimal number to a binary number. Generally, the base multiplication and division are used. The integer and decimal parts are converted respectively, and the last two parts are combined to form the converted binary number.
The integer part is converted by the base division, that is, dividing by the base 2 of the binary number to take the remainder, and then dividing its quotient by 2 to take the remainder. repeat this process until the quotient is 0. The first remainder is the decimal bit of the binary number, increasing sequentially. The last remainder is the highest bit of the binary number.
The fractional part is converted by the base multiplication, that is, multiplying the base 2 to take the integer, and then multiplying the remaining decimal places by 2 to take the integer, until the expected precision is reached (the decimal part conversion may have an infinite loop or an infinite non-loop ). The first integer is the first of the decimal places in the binary system. The last integer is the decimal places in the binary system.
Because the bitwise of any base number is expressed in decimal number, can any base number be converted into an equivalent decimal number?
(3) Conversion between numbers
● How to convert the decimal number to binary or octal
To convert a decimal number to a binary number, use 2 to remove the decimal number again and again until the quotient is 0. Then, read the obtained remainder from the last remainder, that is, "Remove 2 from the remainder ".
For example, convert 41 to binary
1 0 1 0 0 1 more
0125102041
That is, (41) d = (101001) B
Decimal conversion to octal rules: similar to binary, "except for octal remainder ".
Example: 41 to octal
More than 51
0541
That is, 41 is converted to 51.
● How to convert binary and octal to decimal
Convert binary to decimal: (A1... An-1an) 2
= (A1 × 2 ^ (n-1) +... + An × 2 ^ 0) 10
Octal to decimal: (A1... An-1an) 8
= (A1 × 8 ^ (n-1) +... + An-1X8 ^ 1 + an X 8 ^ 0) 10
Example: (10001010) 2 = (1X2 ^ 7 + 0x2 ^ 6 + 0x2 ^ 5 + 0x2 ^ 4 + 1X2 ^ 3 + 0x2 ^ 2 + 1 × 2 ^ 1 + 0 × 2 ^ 0) 10 = (138) 10
(532) 8 = (5x8 ^ 2 + 3x8 ^ 1 + 2x8 ^ 0) 10 = (346) 10
● How to convert binary and octal values
Binary octal rule: group the decimal number from low to high. Each group contains three digits, which can represent numbers ranging from 0 to 7. In turn, write down the numbers represented by each group.
Example: (11001001) 2 = (011) (001) (001)
3 1 1
= (311) 8
Octal binary rules: Each octal digital is represented by a three-digit binary number, and the useless leading 0 is removed from the sequence composed of 0 and 1.
Example: (5163) = (101) (001) (110) (011) = (101001110011) 2

Related Keywords:
Related Article ## Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018 ## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China ## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD