62

1/10(decimal) = 0.0001100110011... (binary)

How do I do that? Am I supposed to convert to binary and then divide? Could someone show me?

3
  • Can you expand on what you mean by "binary"? "Converting to binary" doesn't really make sense. Are you trying to convert the result of a division operation to a floating-point number? Commented Feb 13, 2011 at 21:59
  • 2
    @Michael Petrotta- I think he means how you express a fraction in base 2 as a (possibly repeating) decimal. Commented Feb 13, 2011 at 22:01
  • kakopa.com/convert2binary.htm Commented Apr 23, 2014 at 20:00

6 Answers 6

102

In university I learned it this way:

  1. Multiply by two
  2. take decimal as the digit
  3. take the fraction as the starting point for the next step
  4. repeat until you either get to 0 or a periodic number
  5. read the number starting from the top - the first result is the first digit after the comma

Example:

0.1 * 2 = 0.2 -> 0
0.2 * 2 = 0.4 -> 0
0.4 * 2 = 0.8 -> 0
0.8 * 2 = 1.6 -> 1
0.6 * 2 = 1.2 -> 1
0.2 * 2 = 0.4 -> 0
0.4 * 2 = 0.8 -> 0
0.8 * 2 = 1.6 -> 1
0.6 * 2 = 1.2 -> 1
Result: 0.00011(0011) periodic.
5
  • 3
    Where are you getting 0.1,0.2, 0.4, 0.8, 0.6, etc..?
    – Strawberry
    Commented Feb 13, 2011 at 22:23
  • 2
    From the previous row, it is the result. The first row takes the input (in case of this example, 0.1). Just follow the instructions.
    – Femaref
    Commented Feb 13, 2011 at 22:25
  • irritate's answer below shows why this works Commented Jan 23, 2014 at 12:30
  • 5
    Excellent answer. You may be interested to know that this method is not restricted to conversion to binary but will also work for other bases (octal and hexadecimal). Here is an example converting 0.1 to octal: 0.1 * 8 = 0.8 -> 0 0.8 * 8 = 6.4 -> 6 0.4 * 8 = 3.2 -> 3 0.2 * 8 = 1.6 -> 1
    – GoofyBall
    Commented Feb 12, 2014 at 0:22
  • There's a Python implementation of this algorithm here. Commented May 3, 2015 at 14:54
24
 1              1
-- (dec)  =   ---- (bin)
10            1010


       0.000110011...
      -------------
1010 | 1.0000000000
         1010
       ------
         01100
          1010
         -----
          0010000
             1010
            -----
             01100
              1010
             -----
              0010
1
  • 1
    The long division actually shows why the algorithm in the accepted answer works. Commented Jan 23, 2014 at 12:29
21

This may be somewhat confusing, but the decimal positions in binary would represent reciprocals of powers of two (e.g., 1/2, 1/4, 1/8, 1/16, for the first, second, third and fourth decimal place, respectively) just as in decimal, decimal places represent reciprocals of successive powers of ten.

To answer your question, you would need to figure out what reciprocals of powers of two would need to be added to add up to 1/10. For example:

1/16 + 1/32 = 0.09375, which is pretty close to 1/10. Adding 1/64 puts us over, as does 1/128. But, 1/256 gets us closer still. So:

0.00011001 binary = 0.09765625 decimal, which is close to what you asked.

You can continue adding more and more digits, so the answer would be 0.00011001...

1
  • 1
    Thanks, 0b0.1 -> 1/2 , 0b0.01 -> 1/4 , ... Commented Mar 1, 2022 at 7:26
13

Here is how to think of the method.

Each time you multiply by 2, you are shifting the binary representation of the number left 1 place. You have shifted the highest digit after the point to the 1s place, so take off that digit, and it is the first (highest, therefore leftmost) digit of your fraction. Do that again, and you have the next digit.

Converting the base of a whole number by dividing and taking the remainder as the next digit is shifting the number to the right. That is why you get the digits in the opposite order, lowest first.

This obviously generalizes to any base, not just 2, as pointed out by GoofyBall.

Another thing to think about: if you are rounding to N digits, stop at N+1 digits. If digit # N+1 is a one, you need to round up (since digits in binary can only be a 0 or 1, truncating with the next digit a 1 is as inaccurate as truncating a 5 in decimal).

1
  • 2
    Excellent. Femaref's answer seems magical without this explanation.
    – Ray Zhou
    Commented Mar 31, 2017 at 19:53
11

Took me a while to understand @Femaref ('s) answer so thought I would elaborate.

Elboration

You want to convert decimal 1/10 which equal 0.1 to binary. Start with 0.1 as your input and follow these steps:

  1. Multiply input by 2 (mult column)
  2. Take decimal from answer (answer column) as the digit (binary column)
  3. Take the fraction (fraction column) as the input for the next step
  4. Repeat steps 1, 2 and 3 until you either get to 0 or a periodic number. The start of periodic number in this case is shown in last column so we can stop there. But I continued to show the repetition for clarity.
  5. The answer is the numbers taken from the binary column starting at the top.

In this case it is:

0.00011(0011) Note: numbers within parenthesis will keep repeating (periodic)

+-------+-------+--------+---------+----------+--------+----------------------+
| input | mult  | answer | decimal | fraction | binary |                      |
+-------+-------+--------+---------+----------+--------+----------------------+
|   0.1 |  2    |    0.2 |    0    |     .2   |      0 |                      |
|   0.2 |  2    |    0.4 |    0    |     .4   |      0 |                      |
|   0.4 |  2    |    0.8 |    0    |     .8   |      0 |                      |
|   0.8 |  2    |    1.6 |    1    |     .6   |      1 |                      |
|   0.6 |  2    |    1.2 |    1    |     .2   |      1 |                      |
|   0.2 |  2    |    0.4 |    0    |     .4   |      0 |                      |
|   0.4 |  2    |    0.8 |    0    |     .8   |      0 |                      |
|   0.8 |  2    |    1.6 |    1    |     .6   |      1 |                      |
|   0.6 |  2    |    1.2 |    1    |     .2   |      1 | < Repeats after this |
|   0.2 |  2    |    0.4 |    0    |     .4   |      0 |                      |
|   0.4 |  2    |    0.8 |    0    |     .8   |      0 |                      |
|   0.8 |  2    |    1.6 |    1    |     .6   |      1 |                      |
|   0.6 |  2    |    1.2 |    1    |     .2   |      1 |                      |
+-------+-------+--------+---------+----------+--------+----------------------+
0

While the algorithm mentioned in answer works for non-recurring rational decimal, i would like to give a more general approach:

Convert any decimal(only rational) to fractional form:

  • numbers like 0.123 is converted to 123/1000
  • numbers like 0.10̅1̅3̅5 which expands to 0.10135135135.. is converted to 10125/99900 and simplified if required(let x=0.10̅1̅3̅5, 100x=10.̅1̅3̅5,100000x=10135.̅1̅3̅5, so x=10125/99900=15/148)
  • convert numerator and denominator to binary after simplification,
    =1111/10010100
  • carry out binary longdivision like decimal,with binary subractions

For non rational decimals:

  • approximation or calculation in binary itself is only way,eg: pi, calculate infinite series pi in binary itself,or approximate to values like 22/7

Fractional binary to decimal general,efficient:

  • convert it to rational form, like 0.10̅1̅0̅0̅1 which would mean 0.1010011001... to fractional: by x=0.101001 2^2 x=10.1001 2^6 x=101001.1001 2^6x-2^2x=100111 60x(decimal)=10011(binary) 60x(decimal)=39(decimal) x=13/20=0.65

Notes:

  • a recurring decimal is always recurring in binary, but need not be when base is power 3,6,7,9 etc.
  • A non recurring decimal in binary if its fractional form contains atleast one 5 in prime factorisation of denominator
  • A recurring binary may or may not be recurring decimal
  • A non recurring binary is non recurring decimal
  • A rational number with denominator of form just 2^x is terminating in binary and decimal, of form 2^x 5^y is non terminating in binary,but in decimal, of any other form is non terminating in both

Not the answer you're looking for? Browse other questions tagged or ask your own question.