# Conversion of binary, decimal, and hexadecimal

Source: Internet
Author: User

The binary uses only the numbers 0 and 1, where each number corresponds to one bit (bits). In general, we will use each 4-bit or 8-bit as a group, which is called half-byte (nibble) and Byte, respectively.

We are interested in the binary value corresponding to the decimal value 110 binary with 10 as the base, we began to use since kindergarten

It out. The bits is arranged in a right-to-left order, with each shift to the left, and the bit value doubled.

Table 2-1 lists the decimal values that are represented in the half-byte and bytes. Don't forget, the half-byte contains 4 bits, and the bytes contain 8 bits.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/57/52/wKioL1SX2SiyDeDRAAB9F28NZxU324.jpg "title=" Qq20141222163755.png "alt=" Wkiol1sx2siydedraab9f28nzxu324.jpg "/>

This means that if the value of a bit is 1, the decimal value corresponding to the half-byte or byte should be computed, and its bit value should be

A bit value with a value of 1 is added. If 0, it is not considered.

This is described in more detail below. If each bit of the half byte is 1, the 8, 4, 2, and 1 are added and the result is 1511

The maximum value of the half byte. Assuming that the value of the half byte is 1010, the accession value of 8 and 2 corresponds to a bit of 1, then the corresponding decimal value is

10. If the value of the half byte is 0110, the corresponding decimal value is 6, because the bit value 4 and 2 correspond to a bit of 1.

However, the maximum value of a byte is much larger than 15, because if every bit in the byte is 1, it is the following value (remember that the word

section contains 8-bit):

11111111

At this point, to calculate the decimal value for the byte, add the bit values for all the bits with a value of 1, as follows:

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

This is the maximum possible value for the byte.

Binary numbers can also correspond to many other decimal values, as shown in some examples below. Suppose the binary number values are as follows:

10010110

Which bits are valued at 1? The answer is a bit with a bit value of 128, 16, 4, and 2, so just add these bit values: 128+ 16+4+

2= 150. For example, suppose the binary number values are as follows:

01101100

Which bits are valued at 1? The answer is a bit with a bit value of 64, 32, 8, and 4, so just add these bit values: 64+32+8+4=

108. Furthermore, if the binary number values are as follows:

11101000

Which bits are valued at 1? The answer is a bit with a bit value of 128, 64, 32, and 8, so just add these bit values: 128+64+32+8=232.

You should keep in mind the contents of table 2-2 before you read the 3rd and 4th chapter on IP-related content.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/57/54/wKiom1SX1YqiuecuAACryLCWXos127.jpg "title=" Qq20141222162415.png "alt=" Wkiom1sx1yqiuecuaacrylcwxos127.jpg "/>

The hexadecimal address is completely different from binary and decimal, and we convert the binary to 16 by reading the half byte. Pass

Half-byte, we can easily convert the binary to 16 binary. The first thing to understand is that hexadecimal only uses the number 0-9,

Instead of using 10, 11, 12, etc. (because they are two digits), use a, B, C, D, E, and F to represent 10, 11,

12, 13, 14 and 15.

Decimal uses 10 digits, and Hex uses the first 6 letters of the alphabet, the a-f.

Table 2-3 lists the binary values and decimal values for each hexadecimal digit.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/57/54/wKiom1SX1gOT9NxGAACWK3t-OKs684.jpg "title=" Qq20141222162724.png "alt=" Wkiom1sx1got9nxgaacwk3t-oks684.jpg "/>

The first 10 hexadecimal digits (0-9) are the same as the corresponding decimal values, do you notice? Therefore, these values are converted to non-

Often easy.

Suppose there are 16 decimal ox6a (sometimes Cisco likes to add an ox to a character before it lets you know that they are hexadecimal values.) Ox

There is no other special meaning), what is the corresponding binary value and decimal value? You just have to remember that each hex character typeface

When the half-byte, and two hexadecimal characters are equal to one byte. To calculate the binary value that corresponds to the hexadecimal number, you can use these two

The characters are converted to half bytes, and then they are combined into one byte: 6=0110, and A= 1010, so the entire byte is 01101010.

To convert from binary to 16, you simply divide the bytes into half bytes, and the following explains this → point in detail.

Suppose there is a binary number 01010101. First divide it into half bytes 0101 and 0101, and these half-byte values are 5 because

The bits corresponding to the value 1 are 1 and 4, respectively. Therefore, its hexadecimal representation is Ox55. To convert the binary number 01010101

As a decimal number, the method is 64 + 16 + 4 + 1 = 85.

Here is another binary number:

11001100

where 1100=12, 1100 = 12, so it corresponds to a hexadecimal number of CC. When you convert it to decimal, the answer is 128+64+

8 +4 =204

An example is given below, assuming that there are two binary numbers:

10110101

It corresponds to a hexadecimal number of OxB5, because the hexadecimal value of 1011 corresponds to B, and 0101 corresponds to a hexadecimal value of 5. Put it

When converted to decimal, the result is 128+32+ 16+4+ 1 = 181.

Conversion of binary, decimal, and hexadecimal

Related Keywords:

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.