**The conversion between decimal and binary**

(1) Decimal conversion to binary, divided into integers and decimal parts

① integral number of parts

Method: In addition to 2, in reverse order, that is, each part of the integer divided by 2, the remainder is the number on the right, and the quotient continues to divide by 2, and the remainder is the number on the last bit, and this step continues until the quotient is 0, reading from the last remainder to the first remainder at the last reading. Here are some examples:

Example: Converts decimal 168 to binary

The result is that the decimal 168 is converted to binary, (10101000)

The first step is to divide 168 by 2, quotient 84, and the remainder to 0.

The second step is to divide the quotient 84 by 2, and the quotient of 42 is 0.

The third step is to divide the quotient 42 by 2, and the quotient of 21 is 0.

The fourth step, divides the quotient 21 by 2, the quotient 10 remainder is 1.

The fifth step, divides the quotient 10 by 2, the quotient 5 remainder is 0.

The sixth step, divides the quotient 5 by 2, the quotient 2 remainder is 1.

The seventh step, divides the quotient 2 by 2, the quotient 1 remainder is 0.

The eighth step, divides the quotient 1 by 2, the quotient 0 remainder is 1.

The Nineth step, the reading, because the last one is obtained by dividing it several times by 2, so it is the highest, and reads the number forward from the last remainder, that is, 10101000

(2) Division of decimal Parts

Method: By 2 rounding, in order, the decimal part is multiplied by 2, then take the integer part, the remainder of the decimal parts continue to multiply by 2, then take the whole part, the remainder of the decimal part multiplied by 2, until the decimal part

to zero. If you can never be zero, the same as the rounding of decimal numbers, as required to retain the number of decimal places, according to the following one is 0 or 1, the choice, if it is zero, give up, if it is 1, into a position. In other words, 0 homes, 1. Readings to read from the preceding integer to the following integer, for example:

Example 1: Convert 0.125 to Binary

The result: Convert 0.125 into binary (0.001) 2

Analysis: The first step, the 0.125 times 2, 0.25, the whole division is divided into 0, the small number of parts into 0.25;

In the second step, the decimal part is divided into 0.25 times 2, 0.5, the whole part is 0, and the decimal part is 0.5;

In the third step, the decimal part is divided into 0.5 times 2, 1.0, the whole part is 1, and the decimal part is 0.0;

The fourth step, reading, read from the first, read the last one, that is 0.001.

Example 2, convert 0.45 to binary (keep to decimal point fourth)

As you can see from the steps above, when you do multiplication for the fifth time, The result is 0.4, then the fractional part is multiplied by 2, 0.8, 0.8 and multiplied by 2, to 1.6 such a constant ride, the final can not get the decimal part of zero, therefore, this time had to learn the decimal method for rounding, but the binary only 0 and 12, so there are 0 homes 1. This is also the computer in the conversion will produce errors, but because of the number of reserved digits, high precision, so can be ignored.

So we can draw the result that converting 0.45 to a binary limit equals 0.0111.

The method described above is the decimal conversion to binary method, which requires attention:

1 decimal conversion to binary, need to be divided into integers and decimal two parts of the conversion

2 when the integer is converted, with the exception of the 2 method, and the conversion of decimal time, with the use of the 2 rounding method

3) Pay attention to their reading direction

So, from the above method, we can derive a decimal number of 168.125 converts to a binary of 10101000.001, or a decimal number converted to a binary number equal to 10101000.0111.

(3) binary conversion to decimal without integer and sub-number part

Method: According to the weighted addition method, the number multiplied by the right of the binary, and then combined and that is the decimal number. Cases

Converts the binary number 101.101 to a decimal number.

Results: (101.101) 2 = (5.625) 10

We're doing binary conversion to decimal. You need to be aware that

1 to know the weight of binary each bit

2) to be able to find the value of each bit

**Conversion between binary and octal systems**

First, we need to understand a mathematical relationship, that is, 23=8,24=16, while octal and hexadecimal are using this

The relationship derives from a three-bit binary representation of an octal, with a four-bit binary representation of a hexadecimal number.

Next, remember 4 numbers 8, 4, 2, 1 (23=8, 22=4, 21=2, 20=1). Now let's practice the conversion between binary and octal systems.

(1) Binary conversion to octal system

Methods: Take the Triple method, that is, from the decimal point of the binary, to the left (right) every three digits into one, then the three-bit binary is added to the weight, the number is a eight-bit binary number, and then, in order to arrange, the position of the decimal point is unchanged, the number is the number we ask for octal. If you take three digits to the left (right), when you get to the highest (lowest) position, if you can't make up three digits, you can add 0 to the left of the decimal point (the rightmost), the highest bit of the integer (the lowest bit) and fill three bits. Cases

① converts binary number 101110.101 to octal

Get the result: convert 101110.101 to octal 56.5

② converts binary number 1101.1 to octal

Get the result: convert 1101.1 to octal 15.4

(2) Convert octal into binary

Methods: Take a three-way, a octal number is decomposed into three-bit binary number, with three-bit binary to add to the weight of the octal number, decimal position as usual. Cases:

① converts octal number 67.54 to binary

Therefore, converts the octal number 67.54 to a binary number of 110111.101100, or 110111.1011

As you can see from the above problem, the calculation of octal conversion to binary

First, the octal is expanded from left to right, with three digits per bit, and the decimal position unchanged.

Then, each bit expands to 22,21,20 (i.e. 4, 2, 1) three bits to do the dine, that is, ax22+ bx21 +cx20= the number on the bit (a=1 or a=0,b=1 or b=0,c=1 or c=0), the ABC arrangement is the binary number of that bit

Next, convert each bit into binary numbers in order

Finally, we get the number of the octal binary converted into binary.

The above method is binary and octal system interchange, we need to pay attention to when doing the problem is

1 The interchange between them is one with three-bit conversion, which differs from binary and decimal conversions

2 Everyone in doing Tim 0 and go to 0 when you should pay attention to, is the decimal point is the left or the right of the decimal point (that is, the highest number of integers and the lowest digits of decimal) to add 0 or to 0, or you will produce errors

**Three or two binary and hexadecimal conversions**

Method: Similar to binary and octal conversions, is only a (16) and four-bit (binary) conversion, the following specific explanation

(1) binary conversion to hexadecimal

Methods: Take four in one method, that is, from the decimal point of the binary, to the left (right) every four digits into a position, then the four-bit binary is added by weight, the number is a 16-bit binary number, and then, in order to arrange, the position of the decimal point is unchanged, the number is the hexadecimal number we are seeking. If you take four digits to the left (right), when you get to the highest (lowest) position, if you can't make up four digits, you can add 0 to the left of the decimal point (the rightmost), the highest bit of the integer (the lowest bit) and fill four bits.

① Example: Convert binary 11101001.1011 to hexadecimal

Get the result: Convert binary 11101001.1011 to 16 to e9.b

② Example: converts 101011.101 to hexadecimal

So we get the result: Convert binary 101011.101 to 16 to 2B.A

(2) Convert 16 into binary

Method: Take a four-way, the hexadecimal number is decomposed into four-bit binary number, with four-bit binary weight added to the hexadecimal number, the decimal place as usual.

① converts a hexadecimal 6e.2 to a binary number

As a result: converts hexadecimal 6e.2 to binary 01101110.0010 or 110110.001

**Four or eight binary and hexadecimal conversions**

Methods: Generally do not convert directly to each other, the general is to convert octal (or hexadecimal) to binary, and then convert the binary to 16 (or octal), the decimal point position unchanged. So the corresponding conversion please refer to the above binary and octal conversion and binary and hexadecimal turns

**Five or eight binary and decimal conversions**

(1) Octal conversion to decimal

Method: By weight addition method, the number of octal per bit will be multiplied by the right, and then combined with the decimal number.

Example: ① converts octal number 67.35 to decimal

(2) Decimal conversion to octal system

There are two ways to convert decimal to octal:

1) Indirect method: First converts the decimal to binary, and then converts the binary into the octal system.

2 Direct method: As we have said before, the octal system is derived from binary, so we can use the decimal conversion to binary similar method, or integer part of the conversion and decimal parts of the conversion, the following specific explanation:

① integral number of parts

Method: In addition to the 8 method, that is, each time the integer part divided by 8, the remainder is the number on the right, and the quotient continues to divide by 8, and the remainder is the number on the last bit, and this step continues until the quotient is 0, and the last reading, from the last remainder to the first remainder.

② of small Parts

Method: Multiply 8 by the method, the fractional part is multiplied by 8, then take the integer part, the remainder of the fractional part continues to multiply by 8, then take the integer part, the remaining fractional part is multiplied by 8, until the fractional part is zero. If you can never be zero, the same as the rounding of decimal numbers, a temporary name called 3 Homes 4.

Example: Converts a decimal number of 796.703125 to an octal number

Solution: First, this number is divided into the whole number of parts 796 and decimal parts 0.703125

Integral Number of Parts

Division of Small Numbers

So, get the result decimal 796.703125 convert octal to 1434.55

The above method you can verify that you can first convert decimal, and then converted to octal, so see whether the results are the same

**66 or 16 binary and decimal conversions**

Hexadecimal and octal have a lot in common, you can refer to the above octal and decimal conversion to try the conversion between the two systems.