Binary, octal, decimal, hexadecimal conversion, binary hexadecimal

1. Preface

The most boring thing during each holiday is that you don't want to get up or eat. Founder just doesn't want to move, lie in bed, watch the mobile phone, and brush QQ space bored. Although few people are playing QQ space now, however, this kind of habit has never changed until now, and the QQ on the computer is suddenly flashing. I know it's the QQ message sent by Uncle Ding, asking me to go to Chongqing's old man-hatter together, uncle Ding is called uncle because he was teased by girls in our class when he went to school. So I often ridicule him with this, but he never cares.

I am from Hubei, and Uncle Ding is from Sichuan. Both of us have the same taste. They don't eat chilies in this abnormal Guangzhou, it's either super-hot or unbearable.

In my heart, I have always admired uncle ding. He is a high-tech student from Hunan University, majoring in Japanese, first-level Japanese, and sixth-level English. What impressed me more is his college time, there were three boys in their class, and the others were girls. He had no leaves in the flowers, and he did not find a girlfriend. I admired the whole body and reached the ground. His greatest ambition was to go to the island country, after all, if I am a Japanese speaker, I will not be able to go to my mind.

As usual, I had a copybook and discussed what projects we were doing in the company recently. I had an unintentional conversation. He asked me if I knew what binary was, and I said yes, he went on to ask, do you know how to use it? I don't know. Isn't it binary or code writing? After talking about this, Uncle Ding is still so awesome. I only blame myself for learning it, so I have this article.

Binary is a familiar and unfamiliar thing. It seems that very few application programmers currently use it. Now, they use advanced languages to develop programs. Who else uses binary, octal, and hexadecimal, I feel that these are all the things that c and c ++ write some underlying interaction programmers do. I would like to pay tribute to the c and c ++ experts. Today, I have made a wrong shift, now that we are unfamiliar with it, we will study it as a matter of personal interests.

2. What is binary

Binary is a widely used numeric system in computing technology. Binary data is expressed in numbers 0 and 1. Its base is 2, The carry rule is "Two in one", and the borrow rule is "one by one as two", which was discovered by the German Mathematical Philosophy master leveniz in the 18th century. The current computer system is basically a binary system, and data is mainly stored in the computer as a complement. Binary in a computer is a very tiny switch, which uses "on" to represent 1 and "off" to represent 0.

Information Storage Unit

Bit: The minimum unit of measurement data.

Byte: The most common basic unit. one Byte has eight digits.

B7 b6 b5 b4 b3 b2 b1 b0

1 0 0 1 0 1 0 1 = 27 + 24 + 22 + 20 = 149

K Bytes 1 k = 1024 bytes

M (MB) byte 1 M = 1024 K

G (Gib) byte 1G = 1024 M

T (too) byte 1 T = 1024G

Once, I heard people say that a c, c ++ God can install the operating system by inputting 0 and 1. I don't know if it is true.

3. decimal conversion

1234 [10 hexadecimal] 0 1 2 3 4 5 6 7 8 9 0 when the number of digits exceeds 9, it is required to enter 1

1000 + 200 + 30 + 4 = 1*103 + 2*102 + 3*101 + 4*100 = 1234

1011 [binary] 0 1 when the value of the digit exceeds 1, it is required to enter 1

1*23 + 0*22 + 1*21 + 1*20 = 8 + 0 + 2 + 1 = 11

1011 [octal] 0 1 2 3 4 5 6 7 when the number of digits exceeds 7, 1 is required.

1x83 + 1x81 + 1x80 = 512 + 8 + 1 = 521

1011 [hexadecimal] 0 1 2 3 4 5 6 7 8 9 a B C D E F when the number of digits exceeds 15, it is required to enter 1

1*163 + 1*161 + 1*160 = 4096 + 16 + 1 = 4113

Of course, it is the easiest to convert other hexadecimal values to a 10-hexadecimal value. I think you will surely be smart.

4. Binary Conversion

First, let's look at the decimal to binary: After Division 2, we get the remainder and finally put the remainder over 100101.

Example: 37 in decimal format

Therefore, the binary number to be converted is 100101.

Then the bitwise to binary is split into three binary numbers.

For example: [octal] 616

6 split to 110

1 split into 001

6 split to 110

Therefore, the binary number to be converted is 110001110.

Then hexadecimal to binary: A octal bit is split into a four-digit binary number.

For example: [hexadecimal] 616

6 split to 0110

Split 1 to 0001

6 split to 0110

Therefore, the binary number to be converted is 11000010110.

5. octal Conversion

Decimal to octal: After Dividing 8 into the remainder, the remainder is reversed.

At the same time, we can first convert the decimal to binary, and then convert the binary to octal.

For example, 2456 is converted to an octal number: 4630.

2456/8 = 307, remaining 0;

307/8 = 38, more than 3;

38/8 = 4, more than 6;

4/8 = 0, more than 4.

Connect all the remainder in reverse order. The result is 4630.

Therefore, the result of decimal 2456 conversion to octal is 4630.

Binary to octal conversion 7 = 4 + 2 + 1 111 the maximum number of octal values is 7 to binary, Which is exactly 111.

Each of the three binary numbers is a group, which is converted into an octal digit. If the binary number is less than three bits, it is filled with zero.

For example: 10011011

010 011 011

2 3 3

Therefore, the binary 10011011 is converted to octal 233.

Hexadecimal to octal

We can first convert a hexadecimal number to a binary number, and convert it from a binary to an octal value. For example:

3BC24

Corresponding to the binary is:

3 0011

B 1011

C 1100

4 0100

The connection is:

0011 1011 1100 0100

Then, group by three groups:

0 011 101 111 100

01000032.1652.1672.160100004

So the 8-digit system is 35704.

6. hexadecimal conversion

Decimal to hexadecimal: returns the remainder after dividing 16.

At the same time, we can first convert decimal to binary, and then convert binary to hexadecimal.

For example, 1610 is converted to hexadecimal.

Directly convert to hexadecimal:

1610/16 = 100 ...... 10 ();

100/16 = 6 ...... 4;

6/16 = 0 ...... 6;

Therefore: 1610 (10) = 64A (16 ).

Binary to hexadecimal: 15 = 8 + 4 + 2 + 1 1111 the maximum hexadecimal number is F, that is, 15 is converted to binary 1111, which exactly occupies four digits.

A group of four binary numbers is converted into a hexadecimal number. If the binary number is less than three digits, fill it with zero.

For example: 1110011011

0011 1001 1011

3 9 B

Therefore, the binary 1110011011 is converted to the hexadecimal 39B.

Octal to hexadecimal

We can first convert the octal digit to binary and convert it from binary to hexadecimal.

Octal: 1234567

To convert to binary is to convert each number to a three-digit binary: 001 010 011 100 101 110 111

Then, the numbers are grouped by four digits starting from the right side: 0 0101 0011 1001 0111 0111

Then, each four-digit group on the Right corresponds to a hexadecimal number: 053977.

7. Usage of various hexadecimal formats

After talking about so much, there is something to use in these processes. Let's discuss it together !!!

Decimal, of course, is easier for us to use. We used to use decimal, which is beyond doubt.

The binary system is used by computers. 1, 0 indicates enable and disable, and has and does not exist. Machines only know the binary system.

In hexadecimal notation, the memory address space is represented by hexadecimal data, for example, 0x8049324.

In programming, we usually use a 10-digit system.

For example, int a = 100, B = 99;

However, because the representation of data in a computer exists in binary format, sometimes binary can be used to solve the problem more intuitively. However, the binary number is too long. For example, the int type occupies 4 bytes and 32 bits. For example, if the value is 100, the value expressed in the binary number of the int type is:

0000 0000 0000 0000 0110 0100

No one would like to think about or operate on such a long number. Therefore, hexadecimal or octal can solve this problem. Because the larger the hexadecimal value, the shorter the number expression length.

1. An important digital system used in the computer field

2. It is helpful to describe computer theory and design computer hardware circuits. For example, in the logic circuit design, we must consider the completeness of functions, but also the use of as few hardware as possible, the hexadecimal system can play a role in theoretical analysis. For example, a four-bit binary circuit can be a maximum of sixteen States, that is, a hexadecimal form. Only these sixteen States are used or used as many as possible, hardware resources play the greatest role possible.

3. The hexadecimal format is shorter, because during conversion, a hexadecimal number can have four digits at most.

What is the common use of the 8-digit system? I really don't know if I have checked the materials? Let me know.

If you have used linux, you may have seen the permissions for a file: 0777, 0666, and so on.

It may be explained as follows: You have read permission plus 1, write permission plus 2, execution permission plus 4, and the final sum is the permission of a role. Linux has three roles: Owner, group, and other users. Therefore, they are represented by 0777 and 0666.

If binary is used, linux uses three bits to indicate permissions. If you have a certain permission, place 1. for example, if the read permission is only 100, the write permission is 010, the read/write permission is 110, and the read/write permission is 111.

8. End

There are still some advantages for an application programmer to understand this. We are currently developing some advanced languages such as C #, Java, memory allocation, and garbage collection, in this way, we will have more time to focus on processing some business logic. I am at a limited level. If there is anything wrong with this article, please make a brick. If you think this article is good, please give me a thumbs up !!!