Menu Close

Converting Decimal Numbers to Binary Numbers

Posted in C Programming

1. How to Convert the Fractional Part of the Decimal Number to Binary Format

Let’s convert the fractional part of the decimal number 0.75 to binary format.

Fraction part to Binary
Fraction part to Binary

Step 1: Multiply the fractional part by 2.

0.75 x 2 = 1.5

Step 2: Write down the integer part of the result and use the decimal part as the next input.

1.5 –> 1.

Step 3: Repeat steps 1 and 2 until the decimal part becomes 0 or the desired number of digits have been obtained.

0.5 x 2 = 1.0 –> 1.

The binary representation of 0.75 is 0.11.

In summary, to convert the fractional part of a decimal number to binary format, you need to repeatedly multiply the fractional part by 2, write down the integer part of the result, and use the decimal part as the next input until the decimal part becomes 0 or the desired number of digits have been obtained.

2. Converting decimal numbers to binary numbers

Converting decimal numbers to binary numbers can be done using the following steps:

  • Convert the integer part of the decimal number to binary format. This is done by dividing the decimal number by 2 repeatedly, and keeping track of the remainders until the quotient becomes 0. Details here For example, the binary representation of 13 is obtained by dividing 13 by 2 repeatedly: 6 remainder 1, 3 remainder 0, 1 remainder 1. So the binary representation of 13 is 1101.
  • Convert the fractional part of the decimal number to binary format. This is done by multiplying the fractional part by 2 repeatedly, and keeping track of the integer parts until the fractional part becomes 0 or the desired precision is achieved. The binary representation is obtained by writing down the integer parts in order.
Related:   The Binary Representation of Negative Numbers

For example, the binary representation of 0.375 is obtained by

    1. multiplying 0.375 by 2 repeatedly:
    2. 0.75 integer part 0,
    3. 1.5 integer part 1,
    4. 1.0 integer part 1.
    5. So the binary representation of 0.375 is 0.011.
  • Combine the binary representations of the integer and fractional parts. The binary representation of the decimal number is obtained by writing down the binary representation of the integer part, a decimal point, and the binary representation of the fractional part. For example, the binary representation of 13.375 is obtained by combining the binary representation of 13 (1101) and the binary representation of 0.375 (0.011), with a decimal point in between. So the binary representation of 13.375 is 1101.011.

3. Examples

3.1. example 0.625=(0.101)B

0.625*2=1.25======Use Integer 1
0.25*2=0.5========Use Integer 0
0.5*2=1========== Use Integer 1

3.1. example 0.7=(0.1 0110 0110…)B

0.7*2=1.4========Use Integer1
0.4*2=0.8========Use Integer0
0.8*2=1.6========Use Integer1
0.6*2=1.2========Use Integer1
0.2*2=0.4========Use Integer0
0.4*2=0.8========Use Integer0
0.8*2=1.6========Use Integer1
0.6*2=1.2========Use Integer1
0.2*2=0.4========Use Integer0

 

Leave a Reply