Conversion between decimal places and binary decimal places

Source: Internet
Author: User
Tags binary to decimal decimal to binary

Conversion between decimal places and binary decimal places
1. Convert binary to decimal
The basic practice of converting a binary number into a decimal number is to first write the binary number as an expansion of the weighting coefficient, and then sum the values according to the decimal addition Rules. This method is called "adding weights.
Example 1105Converts 110.11 of the binary number to a decimal number.Ii. Convert decimal number to binary number
When converting a decimal number to a binary number, because the integer and decimal number conversion methods are different, first convert the integer and decimal part of the decimal number, and then merge them.
1. convert a decimal integer to a binary integer
To convert a decimal integer to a binary integer, use the "Division 2 remainder, reverse order" method. The specific method is: remove the decimal integer with 2 to get a quotient and remainder; then remove the quotient with 2 to get a quotient and remainder, so that until the quotient is zero, then, the obtained remainder is used as the low-level valid bit of the binary number, and the obtained remainder is arranged in sequence as the high-level valid bit of the binary number.
Example 1107Converts (173) 10 to a binary number.
Solution:2. Convert decimal to binary decimal
To convert decimal places into binary decimal places, use the "take 2 as an integer and arrange them in sequence" method. The specific method is: Use 2 to multiply decimal places to get the product, take out the integer part of the product, and then use 2 to multiply the remaining decimal part to get another product, then, the integer part of the product is taken out until the fractional part in the product is zero or reaches the required precision.
Then, sort the retrieved integers in order. The first integer is used as the high valid bits of the binary decimal places, and the second integer is used as the low valid bits.

[Example 1108]Converts (0.8125) to binary decimal places.
Solution:

Example 1109(173.8125) 10 = () 2
Solution:Obtained from [Example 1107] (173) 10 = (10101101) 2
Obtained from [Example 1108] (0.8125) 10 = (0.1101) 2
Combine the integer and decimal parts to: (173.8125) 10 = (10101101.1101) 2

 

Reference: http://zyk.thss.tsinghua.edu.cn/29/elecTec/resource/knowledge/zsd11/z1103.htm

To convert decimal places into binary decimal places, use the "take 2 as an integer and arrange them in sequence" method. The specific method is: Use 2 to multiply decimal places to get the product, take out the integer part of the product, and then use 2 to multiply the remaining decimal part to get another product, then, the integer part of the product is taken out until the integer part in the product is zero or the integer part is 1. At this time, 0 or 1 is the last bit of binary. Or until the required precision is reached.
Then, sort the retrieved integers in order. The first integer is used as the high valid bits of the binary decimal places, and the second integer is used as the low valid bits.
Decimal decimal to binary
For example, 0.625 = (0.101) B
0.625*2 = 1.25 ===== retrieve integer part 1
0.25*2 = 0.5 ======= retrieve the integer part 0
0.5*2 = 1 =========== retrieve integer part 1

Another example: 0.7 = (0.1 0110 0110...) B
0.7*2 = 1.4 ======= retrieve integer part 1
0.4*2 = 0.8 ======= retrieve the integer part 0
0.8*2 = 1.6 ======= retrieve integer part 1
0.6*2 = 1.2 ======= retrieve integer part 1
0.2*2 = 0.4 ======= retrieve the integer part 0
0.4*2 = 0.8 ======= retrieve the integer part 0
0.8*2 = 1.6 ======= retrieve integer part 1
0.6*2 = 1.2 ======= retrieve integer part 1
0.2*2 = 0.4 ======= retrieve the integer part 0

Reference: http://whudongyang.iteye.com/blog/1208120

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.