Home > Common Problem > body text

How to convert hexadecimal to decimal

Release: 2020-09-05 14:48:07
1023844 people have browsed it

The method of converting hexadecimal to decimal: first determine a hexadecimal number; then calculate the weight of the 0th and 1st digits; then on the Nth digit, indicate that the size is " X * 16" to the Nth power; finally calculate the conversion result through vertical expression.

How to convert hexadecimal to decimal

1. Hexadecimal to decimal:

The weight of the 0th digit of the hexadecimal number is 16 raised to the power 0, the weight of the first position is 16 raised to the power 1, and the weight of the second position is 16 raised to the power 2...

So, in the Nth (N starts from 0 ) position, if it is a number X (X is greater than or equal to 0, and X is less than or equal to 15, that is: F), the size represented is the Nth power of

Example: Convert 2AF5 to decimal:

Use vertical calculation:

0th digit: 5 * 16^0 = 5

th 1st digit: F * 16^1 = 240

2nd digit: A * 16^2= 2560

3rd digit: 2 * 16^3 = 8192

The direct calculation is:

5 * 16^0 F * 16^1 A * 16^2 2 * 16^3 = 10997

#2. Hexadecimal to binary:

Since in the binary representation method, the maximum value of the number represented by every four digits corresponds to 15 in hexadecimal, that is, the maximum value of each digit in hexadecimal, so, we can get Come up with a simple conversion method, convert each digit in hexadecimal to four digits in binary, and you will get what you want:

Example: Convert 2AF5 to binary:

0th digit: (5) 16 = (0101) 2

1st digit: (F) 16 = (1111) 2

2nd digit: (A) 16 = (1010) 2

3rd place: (2) 16 = (0010) 2

Get: (2AF5)16=(0010.1010.1111.0101)2

3, ten Convert hexadecimal to octal:

First convert hexadecimal to binary, then convert binary to octal

4. Convert binary to octal:

Take the three-in-one method, that is, starting from the binary decimal point as the dividing point, take every three digits to the left (right) into one digit, and then add these three binary digits according to weight, and the resulting number is one digit. The eight-digit binary number is then arranged in order, the position of the decimal point remains unchanged, and the number obtained is the octal number we are looking for.

If you take three digits to the left (right) and get to the highest (lowest) digit, if you cannot make up the three digits, you can use the leftmost (rightmost) of the decimal point, which is the highest digit of the integer ( The lowest bit) is added with 0 to make up to three digits.


Convert the binary number 101110.101 to octal

Get the result: Convert 101110.101 to octal to 56.5

Convert the binary number 1101.1 to octal

Get the result: Convert 1101.1 to octal to 15.4

MoreConvert binary 110000 to hexadecimalPlease pay attention to the PHP Chinese website.

The above is the detailed content of How to convert hexadecimal to decimal. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
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
Popular Tutorials
Latest Downloads
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!