How to convert one of the decimal points of the soft test to binary

Soft test points:

How to convert decimals to binary (reproduced)

https://jingyan.baidu.com/article/eb9f7b6dc692e9c79264e878.html

Method 1: Use paper and pen to calculate

  1. The decimal fraction is converted into a binary fraction, mainly by multiplying the decimal part by 2 and taking the integer part until the decimal point is 0. Let's take the decimal 0.625 as an example and convert it to binary.

    How to convert decimals to binary

  2. Multiply the fractional part 0.625 by 2, and take the integer part 1, as shown in the figure:

    How to convert decimals to binary

  3. Multiply the remaining fractional part by 0.25 by 2, and take the integer part 0, as shown in the figure:

    How to convert decimals to binary

  4. Multiply the remaining fractional part 0.5 by 2, and take the integer part 1, as shown in the figure:

    How to convert decimals to binary

  5. At this point, the fractional part is already 0, and the calculation ends. Now, we will write the obtained numbers from top to bottom to get 101, as shown in the figure:

    How to convert decimals to binary

  6. Then we get 0.625 converted to binary decimal, as shown in the figure:

    How to convert decimals to binary

    END

Precautions

  • After some decimals are multiplied by 2, the decimal part has not been able to get 0, such as 0.333333. This only requires a certain degree of accuracy.

Guess you like

Origin blog.csdn.net/zy103118/article/details/109811979