当前位置:网站首页>Hexadecimal conversion summary
Hexadecimal conversion summary
2022-07-05 12:21:00 【A finger leaf next to the giant】
Preface :
In learning the principles of computer composition chapter 2 - Operation method and arithmetic unit , Encountered a binary conversion problem , As a computer student , About binary conversion, we still need to understand clearly , I want to sum it up for a long time , Here are some calculation methods .
General content of the article : Decimal system , Binary system , Interval adjustment , Decimal conversion
Binary 、 octal 、 Hexadecimal to decimal
Integral part :

The fractional part :

Convert decimal to binary 、 octal 、 Hexadecimal :
Integral part :
Decimal to N Base number , With its number pair N Continuous surplus , Until the quotient is zero , Then arrange the remainder in reverse order , The number obtained is N Result after hexadecimal :
As shown in the figure :
Put the decimal number 36926 The process of converting to octal :
I can see from the picture that , Decimal number 36926 The result of conversion to octal is 110076.
The fractional part :
Convert decimal to N Hexadecimal decimals are “ ride N integer , Sequential arrangement ” Law . The specific way is :
Arrange the integer parts in order , First take the integer as N The high digit of a decimal , Take the integer taken out as the low-order number , So you get N Decimal number .
As shown in the figure :
Put the decimal number 0.930908203125 The process of converting to octal decimal :
Decimal number 0.930908203125 The result of converting to octal decimal is 0.7345.
Binary and octal 、 Hexadecimal conversion :
octal :
Octal as a written form of binary , The base number is 8, Yes 0~7 common 8 A different number symbol , Count " Every eight enters one. ", because r=8=2 The third power of , So as long as the three digits in binary are grouped into a group, it is an octal digit , The conversion between the two is very convenient .
Hexadecimal :
Hexadecimal is also a common writing form of binary , The base number is 16,“ Every 16 to one ”. Each number is desirable 0~9,A,B,C,D,E,F Any one of , among A,B,C,D,E,F respectively 10 ~ 15 . because r=16=2 Of 4 Power , therefore 4 It is a binary number corresponding to a hexadecimal number .
Actually , Any conversion between hexadecimals can use the method mentioned above , But sometimes it's troublesome , Therefore, different methods are generally adopted for different hexadecimals . There is a very simple way to convert binary to octal and hexadecimal , vice versa .
- Conversion between binary and octal integers
When converting binary integers to octal integers , Convert every three binary digits into one octal digit , The order of operations is from low to high , If the high position is less than three digits, fill them with zeros . The following figure shows how to convert binary integers 1110111100 Convert to octal :

As you can see from the diagram , Binary integer 1110111100 The result of conversion to octal is 1674.
When converting octal integers to binary integers , The idea is the opposite , Each octal digit is converted to three binary digits , The order of operations is also from low to high . The following figure shows how to convert octal integers 2743 Convert to binary :

As you can see from the diagram , Octal integer 2743 The result of converting to binary is 10111100011.
- Conversion between binary and hexadecimal integers
When converting binary integers to hexadecimal integers , Convert every four binary digits to one hexadecimal digit , The order of operations is from low to high , If the high position is less than four digits, fill them with zeros . The following figure shows how to convert binary integers 10 1101 0101 1100 Convert to hex :

As you can see from the diagram , Binary integer 10 1101 0101 1100 The result of conversion to hexadecimal is 2D5C.
When converting a hexadecimal integer to a binary integer , The idea is the opposite , Each hexadecimal digit is converted to four binary digits , The order of operations is also from low to high . The following figure shows how to convert hexadecimal integers A5D6 Convert to binary :

As you can see from the diagram , Hexadecimal integer A5D6 The result of converting to binary is 1010 0101 1101 0110.
stay C In language programming , Binary system 、 octal 、 There is little conversion between hexadecimals , So here we only talk about the conversion of integers , It is enough for everyone to apply what they have learned . in addition , There is also very little direct conversion between octal and hexadecimal , We won't explain it here .
This article refers to the following documents , Predecessors summed up very well , In order to preserve , On the other hand, let yourself have a sorting process , I recorded this article .
Reference documents
边栏推荐
- Mmclassification training custom data
- MySQL regular expression
- MySQL index - extended data
- Automated test lifecycle
- Correct opening method of redis distributed lock
- Read and understand the rendering mechanism and principle of flutter's three trees
- POJ-2499 Binary Tree
- MySQL stored procedure
- Third party payment interface design
- 查看rancher中debug端口信息,并做IDEA Remote Jvm Debug
猜你喜欢

The evolution of mobile cross platform technology

强化学习-学习笔记3 | 策略学习

Redis's memory elimination mechanism, read this article is enough.

Understand redis persistence mechanism in one article

Learn the memory management of JVM 02 - memory allocation of JVM

Interviewer: is acid fully guaranteed for redis transactions?

Uniapp + unicloud + Unipay realize wechat applet payment function

Learn memory management of JVM 01 - first memory

Multi table operation - sub query

MySQL index - extended data
随机推荐
MySQL stored procedure
ZABBIX customized monitoring disk IO performance
MySQL log module of InnoDB engine
II. Data type
Linux安装部署LAMP(Apache+MySQL+PHP)
[untitled]
Complete activity switching according to sliding
Embedded software architecture design - message interaction
Hiengine: comparable to the local cloud native memory database engine
July Huaqing learning-1
Matlab label2idx function (convert the label matrix into a cell array with linear index)
MySQL trigger
嵌入式软件架构设计-消息交互
ABAP table lookup program
Check the debug port information in rancher and do idea remote JVM debug
POJ-2499 Binary Tree
Time tools
Correct opening method of redis distributed lock
Swift - add navigation bar
Principle and performance analysis of lepton lossless compression