Discussion on conversion between decimal and binary decimals

  • 2020-05-12 02:55:57
  • OfStack

1. Convert a base 2 number to a base 10 number

The basic way to convert a base 2 number into a base 10 number is to write the base 2 number as a weighted coefficient expansion and then sum it according to the rule of base 10 addition. This is called additive by weight.

2. Convert from base 10 to base 2

When converting a base 10 number to a base 2 number, the integer and decimal parts of a base 10 number are converted separately and then merged, since the conversion methods are different for integers and decimals.

1. Convert a base 10 integer to a base 2 integer

A decimal integer is converted to a decimal integer of two using the "remainder by two, reverse order" method. The method is as follows: divide the decimal integer by 2, you can get a quotient and remainder; Divide the quotient by 2, and you get another quotient and remainder, and so on, until the quotient is zero, and then arrange the remainder as the least significant bit of the base 2, and the remainder as the most significant bit of the base 2.

2.10 decimal convert to 2 decimal

Conversion from decimal to decimal using the "multiply 2 round, order" method. You take out the integer part of the product, and then you multiply the remaining decimal part by 2, and you get another product, and then you take out the integer part of the product, and so on, until the decimal part of the product is zero, or the desired precision is achieved.

The integers are then sorted in order, with the first integer being the highest significant bit of the decimal in base 2 and the last integer being the lowest significant bit.

Case 1109 (173.8125) 10 = () 2

(173) 10 = (10101101) 2

According to [example 1108], (0.8125) 10 = (0.1101) 2

Combine the whole and fractional parts to get: (173.8125) 10 = (10101101.1101) 2

Decimal decimal →→→→→ →2 decimal method: "round by 2"

Multiply the decimal part by 2 to get the integer part and the decimal part. The integer part is the corresponding base 2 digit, and then multiply the decimal part by 2 (before and after multiplying to get the new decimal part) to get the integer part and the decimal part.

This is repeated until the decimal part is 0 or reaches the accuracy requirement. The first result is the highest bit, and the last result is the lowest bit

For example, the base 2 of 0.25

0.25*2=0.5 is 0
0.5 times 2 is 1.0, which is 1
In other words, the base 2 of 0.25 is 0.01 (the highest bit is obtained in the first time, and the lowest bit is obtained in the last time)

The base 2 of 0.8125

0.8125*2=1.625 is 1

0.625 times 2 is 1.25 rounded to 1

0.25*2=0.5 is 0

0.5 times 2 is 1.0, which is 1

That is, the base 2 of 0.8125 is 0.1101 (the highest bit is obtained in the first time, and the lowest bit is obtained in the last time).

Decimal in decimal decimal →→→→→ →8 decimal method: "round by 8"

0.71875) 10 = (0.56) 8

0.71875 * 8 round = 5.75 5

0.75 * 8 round = 6.0 6

That is 0.56

Decimal decimal →→→→→106 decimal decimal method: "round by 16", e.g.

(0.142578125)10=(0.248)16

16 * 0.142578125 = 2.28125 integer 2

16 * 0.28125 = 4.5 integer 4

16 * 0.5 = 8.0 integer 8

That is 0.248

Conversion between non-decimal Numbers

(1) conversion between base 2 Numbers and base 8 Numbers

The conversion method is: with the decimal point as the boundary, to the left and right of every 3 hexadecimal number of 2 into 1 hexadecimal number of 8, or every 1 hexadecimal number into 3 hexadecimal number of 2, less than 3 fill 0. Such as:

(423. 45) 8= (100 010 011.100 101) 2

(1001001.1101) 2= (001, 001, 001.110, 100) 2= (111.64) 8

(2) conversion from base 2 to base 106

Conversion method: with the decimal point as the boundary, the decimal point can be divided into 106 digits for every 4 digits, or the decimal point can be divided into 4 digits for every 1 digit. If the decimal point is less than 4 digits, 0 can be added. Such as:

(ABCD.EF) 16= (1010 1011 1100 1101.1110 1111) 2

(101101101001011.01101) 2= (0101 101101001011.0110 1000) 2= (5B4B.68) 16

You can make 2 in the middle as a transition.


Related articles: