Home>Article> What is the hexadecimal conversion method?

What is the hexadecimal conversion method?

清浅
清浅 Original
2019-04-23 14:08:34 333322browse

The method of base conversion is: binary numbers and hexadecimal numbers can be converted into decimal numbers using the weighted expansion method. The conversion from decimal to R base must be divided into two parts, and the integer part must be divided by R to take the remainder. Until the quotient is 0, the decimal part must be multiplied by R to take the remainder until an integer is obtained.

The base system is the base digit, which should be familiar to anyone who has been exposed to computers. Our commonly used base systems include: binary, octal, decimal and hexadecimal. The difference between them is When calculating numbers, every number is advanced by one digit. For example, the binary system carries one digit every 2, and the decimal system that we commonly use 0-9 carries one digit every 10. Next, I will introduce it to you in detail in the article, I hope it will be helpful to you.

1: Brief description:

Carry counting system: It is a method that people use symbols to count. A carry notation system consists of a set of numerical symbols and two basic factors.

(1) Digital: Use different digital symbols to represent the values of a number system. These digital symbols are called "digital".

(2) Base: The number of digits used in the number system is called the "base".

(3) Weight: The value of each digit in a certain number system is called "weight".

2: The theory of base conversion

1. Convert binary numbers and hexadecimal numbers to decimal numbers: use the weight expansion method

Convert an arbitrary R base number an an-1...a1a0 . a-1 a-2...a-m

into a decimal number. The decimal value is the sum of each digit and its bit weight. The sum of products.

an×R n an-1×R n-1 … a1×R 1 a0×R 0 a-1 ×R-1 a-2×R-2 … a-m×R-m

2: Convert decimal to R base

Converting a decimal number into R base number needs to be divided into two parts:

Integer part: divide by R and take the remainder until the quotient is 0, we get The remainder of is the digit of each binary number, and the remainders are arranged from right to left (arranged in reverse order).

Decimal part: Multiply R to get an integer. The resulting integer is the digit of each binary number. The integers are arranged from left to right (arranged sequentially).

3: Convert hexadecimal to binary

Each hexadecimal number corresponds to four binary digits, expanded bit by bit.

4: Convert binary to hexadecimal

Convert the binary number from the decimal point to the left (for binary integers) or to the right (for binary decimals) into a group of four digits. If there are less than four digits, add zeros.

Three: Specific implementation

1: Convert binary to decimal

The value of any binary number uses its Expressed by bitwise expansion.

For example: Convert the binary number (10101.11)2 to a decimal number.

(10101.11)2=1*24+0*23+1*22+0*21+1*20+1*2-1+1*2-2

=24+22+20+2-1 2-2=(21.75)10

2: Decimal sorting and conversion into binary

Use the "divide by 2 and take the remainder method" to convert decimal integers into binary integers.

That is, divide the decimal integer by 2 to get a quotient and a remainder; divide the quotient by 2 again to get a quotient and a remainder;

and so on until the quotient is equal to zero.

The inverted arrangement of the remainder obtained each time is the corresponding digit of the binary number.

So, the result is the inverse arrangement of the remainder, which is:

(37)10=(a5a4a3a2a1a0)2=(100101)2

3: Decimal Convert decimals to binary decimals

To convert decimal decimals to binary decimals, use the "multiply by 2 and round" method. That is, use 2 to multiply the decimal decimals one by one,

Arrange the integer parts of the products obtained each time in the order of their appearance, and you will get the corresponding binary decimals.

Convert the decimal decimal 0.375 into a binary decimal. The process is as follows:

Final result: (0.375)10=(0.a1a2a3)2=(0.011)2

4: Convert hexadecimal to binary

Since 24=16, each hexadecimal number must be represented by four binary digits, that is, Each hexadecimal digit is represented by four binary digits.

Example: Convert the hexadecimal number (B6E.9) 16 into a binary number:

B 6 E. 9

1011 0110 1110 . 1001

That is (B6E.9)16=(101101101110.1001)2

5: Convert binary number to hexadecimal

Convert binary number to ten The hexadecimal number is a group of four digits from right to left of the integer part of the binary number. Each group is a hexadecimal integer. If there are less than four digits, 0 is added in front;

To convert a binary decimal to a hexadecimal decimal, the binary decimal part is divided into groups of four digits from left to right, and each group is a hexadecimal decimal.

When the last group is less than four digits, the four digits should be filled with 0 at the end.

Example: Binary number (1010101011.0110)2, converted into hexadecimal number:

0010 1010 1011 . 0110

2 A B .6   ##That is: (10 1010 1011.0110)2=(2AB.6)16

Convert decimal to binary:

Used in easy-to-understand terms: multiply this decimal by 2 until the decimal becomes an integer, and then the integer is converted into binary. Then, after multiplying by 2 several times just now, you can convert this binary Just move the decimal point by a few places

Example: 0.75

0.75X2=1.5

1.5X2=3

to get the integer 3, now put 3 Convert to binary, as follows:

3(10)=》11(2)

Get the binary number: 11

Because we just multiplied "2" twice, so The decimal is easy to understand with 2 digits on the left. The final result is: 0.11

Some decimals will never get an integer when multiplied by 2. It depends on the accuracy required. If it is required to retain 3 decimal places, multiply 3 times." 2" is enough, the decimals behind can be ignored, directly convert the directly facing integer part to binary, and then shift it to the left by 3 digits.

And so on....

The above is the detailed content of What is the hexadecimal conversion method?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn