Talk about computer and network common rounding: Binary (binary), Decimal, and Hex (He

Source: Internet
Author: User

Talking about computer and network common carry System: Binary (binary), decimal and hex (hexadecimal)

Binary, decimal, and hexadecimal, these binary decimal digits we are most familiar with the following 10 numbers that are first approached from pre-school or kindergarten to our daily lives almost daily with him.

650) this.width=650; "title=" clip_image002 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "alt=" clip_image002 "src=" Http://s3.51cto.com/wyfs02/M02/6C/AD/wKiom1VP_0mTBCvIAAE-eKQOWUU639.jpg "border=" 0 "height=" 285 "/>

But then again, do you really understand these 10 numbers? Or do you understand the decimal word?

Today we'll take a decimal point and talk about binary, 16, and the transitions between them. Before we talk about these binaries, let's look at the concept of a binary:

The so-called binary system is the carry system, which is a kind of carry-out method stipulated by people. The Carry system/position counting method is a notation, so it is also called the Carry notation/bit value counting method, which can represent all the values with a finite number symbol. The number of digits that can be used is called the Radix or base (radix), and the cardinality is N, which can be called N-binary, or n-binary.

For any kind of carry system---N-binary, it means that the number operation at a certain position is every "n" from right to left. Decimal is every "ten" into one, hexadecimal is every "16" into one, "two" into the system is every two into one, and so on, N is the n-ary. Now the most common is the decimal, usually using 10 Arabic numerals 0-9 to count.

Note: The decimal is 0-9 10 numeric values to be counted, not 1-10, the other binary is also the same n binary is the number of 0--(n-1) to count instead of 0-n.

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/6c/ad/wkiom1vp_0ra0f_raacv8n2ffry468.jpg "border=" 0 "height="/>

count value: equals the value of each cell in the above multiplied by the value of the cell instance, and then adds the value of all the cells.

Take the value of the above example: 1X billion + 2X million + 3X million + 4X 100,000 + 5X million + 6X thousand + 7X white + 8X 10 + 9x1=123456789.

Decimal is very easy to understand because we have been exposed to it since we were young, so we are very familiar with it. What happens if you suddenly get to the binary notation and the daily life is counted in binary? The answer is that you will almost go insane because the binary is generally designed to allow the computer to understand and use it rather than to use it for our daily life, because binary has only two values of 0 and 1 to count, and if a large number is represented by a binary, then it will be a long number. Like 11011011, which makes you look like a rune, and cannot immediately say its value, but the computer does not, it prefers to read the use of this "rune."

In fact, when learning the network, especially when the IP address, you need to really understand the binary and binary and decimal, hexadecimal conversion between, this is very important. The following is the introduction of the binary, it is very simple, the binary only uses the numbers 0 and 1, where each value corresponds to one bit (bits), bits in the right-to-left order, each left to move one bit, the bit value is doubled. We typically use each of the 4-bit or eight-bit as a set, which is called a half-byte (nibble) and a byte (byte), respectively.

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "alt=" image "src=" http://s3.51cto.com/ Wyfs02/m01/6c/ad/wkiom1vp_0uwhlhjaabgqsxpxiu382.jpg "border=" 0 "height=" 104 "/>

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/6c/ad/wkiom1vp_0zh4ktwaacjmjooofk553.jpg "border=" 0 "height="/>

count value: equals the value of the individual cells above multiplied by the value of the actual cell instance, and the value of all the cells is added to the end.

Take the value of the above example: 1X128 + 0X64 + 1X32 + 0X16 + 1X8 + 0X4 + 1x2 + 0x1=

128+0+32+0+8+0+2+0=170

Conversion between binary and decimal

The decimal and binary are described above, and the following describes how they are converted. The following table lists the decimal values that are represented in half-bytes and bytes.

Bit values in half bytes

Bit values in bytes

8 4 2 1

128 64 32 16 8 4 2 1


This means that if the value of a bit is 1, then the decimal value corresponding to the half-byte or byte should be computed, and its bit value should be added to all the bit values that have a value of 1. If 0 is not considered.

If each bit of the half byte is 1, then 8, 4, 2, and 1 are added, resulting in a maximum value of 15-half bytes. Assuming that the value of the half byte is 1010, that is, the corresponding bit value of 1 is 8 and 2, the corresponding decimal value is 8+2=10.

Similarly, the byte conversion method is the same as the half byte, but the value of the byte is much larger than the maximum value of the half byte 15, if each bit of the byte is 1, the value is as follows (byte has 8 bits):

128+64+32=16+8+4+2+1=255.

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/6c/ad/wkiom1vp_02hzs4naadq-zb2hvo871.jpg "border=" 0 "height=" 228 "/>

The decimal-to-binary conversion is the inverse of the above method, as follows:

1. A bits value that is closest to the decimal value and less than the decimal size is first taken.

2. Subtract the approximate value from the decimal value, and the difference is obtained.

3. Follow the first to second step and take the second one, and then the third one.

4. Get the difference of 0.

5. The result of a "or" operation of all the bits and results is the corresponding binary value.

Here is an example to illustrate:

such as decimal 234 is converted to binary.

and 234 the nearest-size bits value is 224 (11100000)

234-224=10

and 10 The closest bits value is 8 (00001000)

10-8=2 (00000010)

Perform and operate on the binary above:

11100000

00001000

00000100

11101100

Conversion between hexadecimal and binary, decimal

Hexadecimal is completely different from binary and decimal, we convert the binary to 16 by reading the half byte. Why is it? Because a half byte exactly satisfies a hexadecimal maximum value of 15. That is, all bits of a half byte are taken 1.

1111, the decimal value is 8+4+2+1=15. Decimal uses 0-9 10 digits and hex in addition to using the decimal 10 number of the other 6 with what instead of? 10, 11, 12, 13, 14, 15? That's not possible, because 10-15 of these 6 numbers are not two digits, so we use a, B, C, D, E, F to represent 10, 11, 12, 13, 14, 15.

Each hexadecimal character is equivalent to half a byte, and two hexadecimal characters are equivalent to one byte. To calculate the binary value that corresponds to the hexadecimal number, you can convert the hexadecimal characters to binary half-bytes, and then merge them into a single byte. Here are a few examples to introduce the hexadecimal and binary, decimal conversion method:

Example 1, hexadecimal 0x7b (typically 0x prefixes represent the number of subsequent 26 binary) to binary and decimal.

Convert to binary:

As mentioned above, each character in hexadecimal is half a byte, we separate to see: 7=0111 and b=1011, so the whole byte is 01111011.

Convert to decimal:

7 x (1) + B x (16) 0 = 112 + 11 = 123.

Instance 2, binary 10110101 is converted to 16 decimal and binary.

Convert to Hex:

First, split 10110101 bytes into two bytes: 1011 and 0101. 1011 corresponds to a hexadecimal character of B (8+0+2+1), 0101 corresponds to a hexadecimal character of 5 (0+4+0+1), so the hexadecimal value is 0xb5.

Convert to decimal:

128 + 32 + 16 + 4 + 1 = 181

In fact, for any number, we can use a different carry system to represent. For example: Decimal 57 (10), can be expressed as a binary 00111001 (2), can also be expressed as a five-decimal 212 (5), or in octal notation 71 (8) in hexadecimal notation 39 (16), they represent the same value, It is only in our daily life that we are accustomed to using decimal notation and the computer is used in binary and hexadecimal notation only!

Well, this is the end of this article, I hope to have just contact with the computer or network field of friends can have a good start!

This article is from the "E-Network Deep" blog, please be sure to keep this source http://jettcai.blog.51cto.com/1447637/1650127

Talk about computer and network common rounding: Binary (binary), Decimal, and Hex (He

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.