Big talk binary, octal, decimal, hexadecimal conversion

Source: Internet
Author: User
Tags decimal to binary

1. Preface

Every time the most boring thing, is not want to get up, do not want to eat, founder is not want to move, lying in bed, looking at the mobile phone, bored brush QQ space, although now very few people play QQ space, but this habit has been kept until now, have not changed, the computer QQ suddenly flashing, I know is Ding sent to the QQ message, called me to eat with the old hemp, Uncle Ding is called uncle, is because of school together, the girls in our class molested a bit, so I often take this to ridicule him, but he also never cared.

I am Hubei, Uncle Ding is Sichuan people, we both taste the same, eat everything to bring a little spicy, in this perverted Guangzhou, they do not eat chili, or is super spicy kind, really can not stand.

In my heart I have been very admire Ding, he Hunan University of the top students, Japanese major, Japanese level, English six level, let me admire is he university, their class on 3 boys, the other are girls, he all the flowers in the leaf not stained body, hard to find a girlfriend, I admire the whole body, His biggest ambition is to go to the island, after all, someone else's Japanese level, if not to the heart also can't get through.

Or as usual, eating a copy of the hand, discussing what we have been doing in the company recently, an unintentional conversation, he asked me to know what is binary, I said know, he went on to ask, do you know how to use it, I said don't know, don't use binary, still can't write code? Said so much after all, Uncle Ding, still so cool, only blame oneself learn and not fine, so have this article.

Binary a familiar and very unfamiliar things, seemingly now the application programmer with really very little, now use high-level language to develop programs, who also use binary, octal, hex, give me the feeling that these are those c,c++ write some of the bottom-up interaction of the programmer to do, to c,c++ The Great God pays tribute, today swim, since feel unfamiliar, then we come to study this thing, is purely personal hobby only.

2. What is a binary

Binary is a kind of system widely used in computing. Binary data is a number represented by 0 and 12 digits. Its base is 2, the rounding rule is "every two in one", the borrow rule is "borrowing one as two", which was found by the 18th century German mathematical philosophy master Leibniz. The current computer system is basically binary systems, the data in the computer is mainly in the form of complement storage. The binary in the computer is a very small switch, with "on" to indicate 1, "off" to represent 0.

Storage unit of information

Bit (bit): the smallest unit of metric data

Byte (byte): most commonly used base unit, one byte has 8 bits

B7 b6 b5 b4 b3 b2 B1 b0

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

K-byte 1k=1024 byte

M (MBytes) byte 1m=1024k

G (RM) byte 1g=1024m

T (too) byte 1t=1024g

Once heard people say, a c,c++ big God, rely on input, 0 and 1 can install the operating system, do not know is true, hey

3. Decimal conversion

1234[10 binary ] 0 1 2 3 4 5 6 7 8 9 0 when the value on the digits is more than 9, go to 1.

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

1011[2 binary] 0 1 When the value on the digits exceeds 1, it's going to be 1.

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

1011[8 binary ]0 1 2 3 4 5 6 7 when the value on the digits is more than 7, go to 1.

1*83+1*81+1*80=512+8+1=521

1011[16 ]0 1 2 3 4 5 6 7 8 9 A B C D E F When the value of the digit is more than 15, it will go to 1.

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

Of course the other conversion into 10 binary is the simplest, I think the smart you will certainly.

4. Binary conversion

First look at the decimal to the binary: Divide the remainder by 2 and the remainder is reversed 100101

For example: decimal number 37

So the converted binary number is: 100101

Then octal to binary : an octal bit split into a three-bit binary number

For example: [Octal]616

6 split into 110

1 split into 001

6 split into 110

So the converted binary number is: 110001110

Then hex to binary: an octal bit split into a four-bit binary number

For example: [Hex]616

6 split into 0110

1 split into 0001

6 split into 0110

So the converted binary number is: 11000010110

5. Eight binary conversion

decimal to octal : Divide the remainder by 8

We can also convert the decimal to binary and then convert the binary into octal

For example: 2456 converted to octal number: 4630

2456/8=307, Yu 0;

307/8=38, Yu 3;

38/8=4, Yu 6;

4/8=0, Yu 4.

All the remainder are connected in reverse to get the result: 4630.

So the decimal 2456 is converted to an octal result of 4630.

Binary to octal conversion 7=4+2+1 1118 binary the largest number is 7 converted to binary exactly 111, which accounts for 3 bits

Each three binary number is a group, turns into an octal digit, if the binary high position is less than 3 bits, fill with 0.

For example: 10011011

010 011 011

2 3 3

So the binary 10011011 is converted to an octal result of 233.

hexadecimal to octal

We can first convert the hexadecimal number to binary, which is converted from binary to octal, for example:

3bc24

corresponding to binary is:

3 0011

B 1011

C 1100

4 0100

To connect it together is:

0011 1011 1100 0100

Then follow each of the three component groups:

0 011 101 111 000 100

0__3__5__7__0__4

So 8 binary is 35704.

6.16 Binary Conversion

decimal to hexadecimal : except 16 to fetch the remainder backwards

We can also convert the decimal to binary and then convert the binary into hexadecimal

For example: 1610 converted to hex.

Go directly to 16 binary:

1610/16=100 ... Ten (A);

100/16= 6 ... 4;

6/16= 0 ... 6;

Therefore: 1610 (Ten) =64a (16).

Binary to hexadecimal 15=8+4+2+1 11,116 The maximum number is F, that is, 15 is converted to binary 1111, which is just 4 bits

Each four binary number is a group, turn into a hexadecimal digit, if the binary high position is less than 3 bits, fill with 0.

For example: 1110011011

0011 1001 1011

3 9 B

So the binary 1110011011 is converted to hex 39B

octal to hexadecimal

We can first convert octal numbers into binary, and convert from binary to hexadecimal

Octal: 1234567

Convert to binary is each number converted to three-bit binary: 001 010 011 100 101 110 111

Then we'll start with the numbers on the right. Four-bit grouping: 0 0101 0011 1001 0111 0111

Then, from the right, each four-bit group corresponds to a 16-digit number: 053977

7. The use of various types of systems

Said so much, these into the system are some what use, we discuss it together!!!

10 , of course, is easy for us to use the human, we have been a small habit of using the decimal, this is undoubtedly.

2 Binary, is for computer use, 1, 0 for open and close, with and without, machine only know 2 binary.

16 Binary, the memory address space is represented by 16 binary data, such as 0x8049324.

In programming, we still use the 10 binary.

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

However, because the data is represented in the computer and eventually in binary form, sometimes binary is used to solve the problem more intuitively. But the binary number is too long. For example, an int type occupies 4 bytes and 32 bits. For example, 100, a binary number expressed in int type would be:

0000 0000 0000 0000 0110 0100

Faced with such a long number of thinking or operation, no one would like it. Therefore, using 16 or 8 binary can solve this problem. Because, the larger the system, the shorter the length of the expression.

1. An important numbering method for the computer field

2. The description of computer theory, the design of computer hardware circuit is very useful. For example, in logic circuit design, we should consider the complete function, but also consider using as little hardware as possible, Hex can play a role in theoretical analysis. For example, four-bit binary circuit, up to 16 states, that is, a hexadecimal form, only these 16 states are used or as much as possible to be used, hardware resources to play the greatest possible role.

3.16 binary is shorter, because when converting a 16 binary number can be the top 4 bits 2 binary number.

8 Binary, what is the general use, check the information, do not know? Tell me about the great God who knows.

If you've ever used Linux, you might have seen this. Represents a file's permissions: 0777, 0666, etc.

There may be this explanation: with Read permission plus 1, with write permission plus 2, with execute permission plus 4, and finally, a role has the permissions. And Linux has three kinds of roles: belong to the main, belong to group, other users, so with 0777, 0666, such as the expression.

If the binary view, Linux with 3 bit to represent the permissions, if you have a certain permission to the position 1. For example, only have Read permission is 100, only have write permission is 010, with read and Write permission is 110, with read and write Execute permission is 111.

8. End

For an application member, there are some benefits to know about these, and we are now developing high-level languages, C#,java, memory allocations, garbage collection, all without our own concern, so we will have more time to focus on the processing of some business logic. I level limited, if there is anything wrong in the text, Welcome to shoot Bricks, the great God do not look, I write this article is just a summary of their own learning process, if you think this article is good, help me to point a praise!!!

Big talk binary, octal, decimal, hexadecimal conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.