当前位置:网站首页>Conversion between binary, octal, decimal and hexadecimal (integer plus decimal)

Conversion between binary, octal, decimal and hexadecimal (integer plus decimal)

2022-06-10 10:41:00 Qin Xuexue

Preface

From now on, for some reason, I want to start learning C Language , Today, the first class that the teacher talked about was decimal calculation . This knowledge point has not been reviewed for a long time , Simply write an article blog Help the brain recall and consolidate .

One 、 Hex brief overview

image-20220607224243566

It can be used Co., LTD. The number symbol of represents be-all Values are Carry system / Position counting method A major feature of the counting method , So it's also called Carry notation / Bit counting .

For any system —X Base number , It means that the number operation on each bit is every X Into one . Decimal system It's every decimal , Hexadecimal It's one every sixteen , Binary system It's two in one , And so on ,x The base is the square x carry .

# Overview from Baidu Encyclopedia

For any number , We can use different carry systems to express . such as : Decimal number 57(10), It can be used Binary system Expressed as 111001(2), It can also be used. Pental Expressed as 212(5), It can also be used. octal Expressed as 71(8)、 Expressed in hexadecimal as 39(16), The values they represent are the same .

Two 、 Common base division methods

The system that we usually encounter the longest in our life or study is Decimal system 、 Binary system 、 octal 、 Hexadecimal , But this is just a common base , It doesn't mean that there are only these bases , There are also some unusual base numbers , Like a year 12 Months , Isn't that what 12 Base number Well . One day 24 Hours , No, it is. 24 Base number Well , Here we focus on common base numbers .

image-20220607230324161

So here comes the question , How to distinguish this modo base ??? a number 100, It can be decimal 100, It can also be binary 4 etc. , Very unclear , That's why we have the following Two ways to distinguish

The first way is Numeric subscript notation , Well understood. , This / The number of strings is in decimal , You just put this / String numbers are enclosed in parentheses , Then identify the corresponding hexadecimal digit at the right subscript of the parenthesis .

for example (1421)10 For decimal ,(11001)2 For binary ,(672534)8 For octal ,(A3CE45)16 For hexadecimal .

The second way is English suffix capital letters , This is the same as Numeric subscript notation The same , It's just that the subscript numbers have become the English initials of each hexadecimal , Here we are required not to memorize words , However, we must find out which base is represented by the capital initial at the beginning of each base .

Binary system B (binary)
octal O (octal)
Decimal system D (decimal)
Hexadecimal H (hexadecimal)

Be careful : When there are no subscript numbers and uppercase hexadecimal initials The default is decimal .

for example (1421) For decimal ,(11001)B=11001B For binary ,(672534)0=672534Q For octal ( If you don't write parentheses, put O Change it to Q, To prevent and 0 Mingle ),(A3CE45)H=A3CE45H For hexadecimal .

3、 ... and 、 Non decimal to decimal

Conversion between different bases , It's essentially Conversion between cardinalities , The method of non decimal to decimal is consistent , That is to count each of you According to the right Expand , also Add to sum Can .

Do you still don't understand , Just look at a few examples ( The words are a little ugly )

eg1. Convert binary to decimal

image-20220609212726410

eg2. Convert octal to decimal

image-20220609214136733

eg3. Convert hexadecimal to decimal

image-20220609214146448

After writing, I suddenly saw that there was a decimal from non decimal to decimal , It's actually the same as an integer , Only the first digit after the decimal point becomes x-1, The second digit after the decimal point becomes x-2, And so on ……

eg4.image-20220609214933401

Four 、 Decimal to non decimal ( Integer plus decimal )

Decimal to non decimal , It's a little different from the previous one , Decimal to non decimal requires The integer part and the decimal part are converted respectively , The splicing shall be carried out after the conversion .

The integer part and the decimal part are converted respectively There must be some conversion skills , The conversion formula is Integral part : Turn and divide , Take the rest , The fractional part : Turn a few times a few , Just take the whole .

eg1. Decimal to binary ( Integers and decimals )

image-20220609221549060

eg2. Decimal to hexadecimal ( Integers and decimals )

image-20220609222336446

notes : Some regulations are accurate to the number of digits , There's no need to leave 0 until , When the accuracy is reached

5、 ... and 、 Binary to octal 、 Hexadecimal ( Integer plus decimal )

Binary to octal 、 Hexadecimal, that is, binary to 2~n~ Base number , We can convert binary to decimal , Then convert the decimal system to octal 、 Hexadecimal , It's just a little slow and low.

Binary to 2n Base number , There is also a separate method , Take binary numbers with integers and decimals for example , That's it Take the decimal point as the boundary Grouping , Integer parts from right to left , The decimal part is from left to right , Every time ~n~ The number of digits is a group ( Not enough decimals n Bit is required 0 Fill up enough n position , Integers don't matter ), Then divide into each group Then calculate according to binary , Last Summarize the splice , We can get the result .

I don't say much nonsense , Let's look at an example ……

eg1. Convert binary to octal

image-20220609225146285

eg2. Convert binary to hexadecimal

image-20220609225206517

6、 ... and 、 octal 、 Hexadecimal to binary ( Integer plus decimal )

Binary to 2~n~ Base number and 2~n~ Base number Converting to binary is actually a Reciprocal processes ,2~n~ Base number Change to binary , Each value of itself can be converted to n Bit binary number represented by binary and spliced .

eg1. Convert octal numbers to binary numbers

image-20220609230550582

eg2. Convert a hexadecimal number to binary

image-20220609230601840

原网站

版权声明
本文为[Qin Xuexue]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101015400272.html