Why is there an error in the computer with decimals? This section describes the machine number, code system, floating point number, and Number System Conversion Problems, and error code system.
1. Commonly Used Number System
Decimal 0 ~ 9
Octal 0 ~ 7
Binary 0 ~ 1
Hexadecimal 0 ~ F
2. Convert the decimal to the hexadecimal notation
Method: divide by the base to obtain the remainder Inverse
3. 2 in hexadecimal notation 8 to hexadecimal notation
Binary
___________________________
2 ^ 3 2 ^ 2 2 ^ 1 2 ^ 0
1 0 0 1 X
= 8 + 1 = 9
Octal
-------------------------
8 ^ 1 8 ^ 0
1 7
= 1*8 + 7*1 = 15
The hexadecimal format is similar.
4. Convert binary to hexadecimal octal
Second to eighth
Three results are combined.
November 16
The result of a group of four digits is merged.
5. Storage of integers in memory, using binary
Symbol bit
Positive number of original codes 0
Negative 1
The positive number of the anticode is the same as the original code.
The negative number is based on the original code, the symbol bit remains unchanged, and each bit is reversed.
The positive value of the complement code is the same as the source code.
The negative number is based on the anticode, And the symbol bit remains unchanged. The last digit is + 1.
Case Study
----------------------------
Source code anti-Code complement
5 0000 0101 0000 0101 0000 0101
-5 1000 0101 1111 1010 1111
6. Number of machines and true values
"+", "-", And absolute values are used to represent the size of a value. A value in this form is called a "true value" in a computer"
After the symbol is digitalized, the highest bit of the binary number "0" indicates the positive number, and "1" indicates the negative number. The value in this form is called the "machine number" in the computer"
The decimal point in the machine number is implicitly not placeholder.
The number of machines has a signed pure integer after the digit
The pure decimal point is placed after the sign bit and before the highest digit.
The unsigned pure integer is placed after the decimal bit.
Before the highest decimal point
7. Storage of decimal places
Small numbers in computers are stored in binary (floating-point number) format.
First, it is a case of converting decimal form into binary.
--------------------------------
0.8125 convert to binary
In fact, this is a coincidence to get a specific value.
--------------------------------
But in some special cases
8. Causes of floating point errors
An error may occur in two minutes.
1) The floating point number is saved as a binary number. Therefore, some decimals with a limit may be converted into an infinite number of decimal places after calculation based on the above method.
--------------------------------
(Decimal) 0.9 to 2 is an infinite loop decimal 0. 1110011001100110011...
--------------------------------
2) the computer has limited precision in storing floating point numbers. For example, float can retain a maximum of 7 digits in decimal format (Binary 23 digits), and double can retain a value in decimal format of 15 ~ A 16-bit (Binary 52-bit) valid number. The valid number is ignored.