60

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? 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. Feb 13, 2011 at 22:01
  • kakopa.com/convert2binary.htm Apr 23, 2014 at 20:00

5 Answers 5

100

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
    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
    Feb 13, 2011 at 22:25
  • irritate's answer below shows why this works Jan 23, 2014 at 12:30
  • 4
    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
    Feb 12, 2014 at 0:22
  • There's a Python implementation of this algorithm here. May 3, 2015 at 14:54
23
 1              1
-- (dec)  =   ---- (bin)
10            1010


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

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
  • Thanks, 0b0.1 -> 1/2 , 0b0.01 -> 1/4 , ... 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
    Mar 31, 2017 at 19:53
9

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 |                      |
+-------+-------+--------+---------+----------+--------+----------------------+

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