Representation and operation of numbers (decimal conversion)

As the basic knowledge of computer introduction, hexadecimal conversion, whether it is a computer basic course, or other subjects related to 0, 1, will involve the problem of hexadecimal conversion, such as digital circuits. Whether you can learn computers, in the computer industry, hex conversion is the first threshold.

First, the numerical representation

  1. The count value of
    the method for counting the carry certain principles referred notation, also called value. For any hexadecimal number x, it can be expressed as follows:
    Insert picture description here
    Looking at this string of formulas, I choose to give up. Classmates, you are not suitable for reading, or choose another way.
    Insert picture description here

① a i is a digital number, and each type of hexadecimal number is represented by a fixed digital symbol. This symbol is called: digital.
Do not understand, is there any rescue?
You need to know:
binary has 2 numbers: 0 and 1;
octal has 8 numbers: 0, 1, 2, 3, 4, 5, 6, and 7;
decimal has 10 numbers: 0 ~ 9 (this is needless to say );
Hexadecimal has 16 numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F (letters are not case sensitive).

That is to say, there is a certain number in a certain number, but you know that their first numbers all start from 0, and ten to fifteen are replaced by letters, mainly to show the personality of hexadecimal.

② i is a digit, and the digit is the position of the exponent code in a number.
For example: octal 123.123, the digits from left to right are: 2, 1, 0, -1, -2, -3.
③ r is the radix. The radix refers to the number of digits that can be used on each digit in a certain counting system.
What is the base number in a sentence.
For example, the base of binary is 2; the base of octal is 8.
④ r i is the weight, and the weight is the power of the radix, which is determined by the number of digits.
For example, in octal 123.123, the weight of the second digit is 1 × 8 2 .

  1. Counting system commonly used in computers is
    expressed in hexadecimal notation:
    ① Enclose the numbers in parentheses, and add the number system to distinguish. For example, octal (112) 8 .
    ② Use suffix to distinguish, binary, decimal, octal and hexadecimal suffixes are B, D, O and H (Note: not case sensitive).

Second, the conversion of
hexadecimal conversion of other hexadecimal to decimal conversion of
any hexadecimal to decimal is particularly simple, just expand according to the right.
For example:
Insert picture description here
② Decimal conversion to other bases
Commonly used are power reduction and multiplication and division. The two methods are actually the same. I personally think that as long as the computing power is strong enough, why bother?
So we don't play cards according to common sense and use our own method to calculate.
For example: 62D converted to binary.
62 and 64 (2 6 ) are relatively close, greater than 32 (2 5 ). Then 62 to binary conversion will have 100,000, 62-32 = 30; 2 4 = 16, there are 110,000; Similarly, 14> 2 3 , then 111,000, the remaining 6; we know that the binary number of 6 is 110. Then 62 is converted to binary 111,110.
What if there is a decimal?
multiplication. For example: 0.5 is converted to binary. 0.5 × 2 = 1, then 0.5 is converted to binary 0.1.
Decimal conversion octal, hexadecimal is the same method.
③Binary and octal conversion.
One octal system needs to use 3 binary systems.
For example: (110) 8 = (001,001,000) 2 ; the leftmost should start from a non-zero number, if it is a signed base, say (110) 8 = (1001000) 2 .
④Binary conversion Hexadecimal The
same reason, a hexadecimal need to use 4 binary.

Third, the operation of the
hexadecimal system is to advance every one. For example: binary, every two enters one.

1. Unsigned operation
Unsigned hexadecimal numbers don't care about the sign. Unsigned actually has no sign at all.
① Arithmetic operation is similar to addition, subtraction, multiplication and division in mathematics. But it must be clear what goes in every time. If you are really confused, first convert to decimal operation to get the result and then convert.
②Logical operation
AND (AND): ∧, there is zero phase and 0, non-zero phase and 1;
OR (OR): ∨, double zero is 0, otherwise 1;
NOT (NOT): ﹣, non-zero is 1, non-1 is 0;
XOR: ⊕, the same is 0, the opposite is 1.

2. Representation of signed binary numbers
You can see here, it is really not easy.
You only need to know that the first number on the left with the sign is the sign bit, 0 is a positive number, and 1 is a negative number.
Signed numbers are divided into original code, inverted code and complement code.
The inverse code, the complement code of the positive number are the same as the original code.
The negative code of the negative number needs to be reversed bit by bit in addition to the sign bit, that is, 0 becomes 1, 1 becomes 0; complements need to add 1.
Original code: 1111,0011
Inverse code: 1000,1100
Complementary code: 1000,1101

Fourth, the complement of the addition and subtraction overflow The
literal meaning of overflow is that the capacity of the container is exceeded, and a part that cannot be filled is lost.
For example: -64D + 64D = 0 with 8-bit word length, [-64] complement = 1100 0000; [64] complement = 0100 0000, the addition result is 1 0000 0000, the result is 9 bits, and the carry 1 is definitely not guaranteed It is overflow.
There are two ways to judge overflow:
① Use symbols to determine whether the result is overflow

If two numbers with the same sign are added and the sign of the result is opposite, it overflows.
If the two numbers with different signs are subtracted, and the sign of the result is the same as the decrement, it overflows.
If two different signs are added or two same signs are subtracted, there is no overflow.

②Use the occurrence of carry during the operation to judge whether the operation result overflows

If a carry or misalignment occurs when the next highest bit and the highest bit are different, it overflows.
If both the next highest bit and the highest bit produce a carry or misalignment, there is no overflow.

5. Representation and operation of
BCD code BCD code is short for binary coded decimal number. Use 4-bit binary to represent 0 ~ 9 in decimal.
①Add and subtract operations of compressed 8421BCD code (one decimal digit becomes four binary digits)
For example: 16D + 18D:
00010110 + 00011000 = 0010 1110.
The decimal adjustment rules for the compressed 8421BCD operation are as follows:

⑴Decimal adjustment rule after addition operation
If the unit of the addition sum is greater than 9 or there is a carry to the tens, you need to "add 06H adjustment", that is, the resulting sum must be added to 00000110B;
if the addition and tens are greater than 9 or to the hundreds To carry, you need to "add 60H to adjust", that is, add 01100000B to the resulting sum.
⑵Decimal adjustment rule after subtraction operation
If the unit of the subtraction difference is greater than 9 or there is a borrow from the tens, you need to "subtract 06H adjustment", that is, the result should be subtracted from 0000 0110B;
if the tens of the subtraction difference is greater than 9 or If there is a carry in the hundreds, you need to "minus 60H", that is, the difference should be subtracted from 0110 0000B.

②Addition and subtraction of uncompressed 8421BCD code (decimal one becomes octet)
Assuming any uncompressed BCD code is expressed as d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 , add / subtract When calculating, if the sum / difference is greater than 9 or d 3 digits have carry / borrow to d 4 digits, the decimal adjustment operation should be performed. Clear the bits
d 4 ~ d 0 to zero, that is, the obtained value is compared with 1111 1111 0000 1111.

Published 19 original articles · Likes2 · Visits 1091

Guess you like

Origin blog.csdn.net/qq_42692319/article/details/103495115