1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Converting .11111 to binary w/o converting to fraction

  1. Aug 27, 2014 #1
    1. The problem statement, all variables and given/known data
    Imagine any recurring decimal in base 10, call it X.

    my question is - can you convert it to binary without rewriting X in fractional form. I know how to do it in fractional form. I know how to convert it to fractional form as well.

    However, I'm curious if one can proceed to solve this problem without converting to fractional form like a/b where a and b are integers.

    2. Relevant equations
    - divide/mult by 2 to convert integer/decimal part to binary

    3. The attempt at a solution
    The reason I ask this is because I know (and can) convert recurring decimals from binary to decimal. However, I'm not aware of any trick that does the other way around (w/o making use of fractions) and if there is one I would like to know how its done.

  2. jcsd
  3. Aug 27, 2014 #2


    User Avatar

    Staff: Mentor

    Hi catluvr. I'm not exactly sure what you seek, or why. But what is special about converting a recurring decimal? It won't generally be an exact equivalent, so I don't see any difference from converting any old decimal fraction into a binary fraction.

    Anyway, this gives me the opportunity to pass on a technique I came up with :smile:
    though I'm sure others have thought of it, too.

    I'll take as an example 0.425718125(10) because I already know it has an exact binary form, I'm working backwards as a check. :approve:

    You probably know about the method for converting a decimal integer into binary by repeatedly dividing by 2? Well, there's a similar technique for converting a decimal fraction into a binary fraction by repeatedly multiplying by 2, and taking note of the digit to the right of the decimal point.

    EDIT I just noticed this is a homework question, so that means you are supposed to figure out the details for yourself. So I have deleted the example I provided below, to leave something you can figure out for yourself ....

    < example redacted >

    You can keep going until you run out of digits or your calculator overflows, then stop. :smile:
    Last edited: Aug 28, 2014
  4. Aug 28, 2014 #3
    I listed it as HW pretty much because I couldn't find anywhere else to put it. It isn't really a homework. It is just me being curious.

    I do know how to convert integer to binary (divide by 2 and collect remainders). I also know how to convert fractional part (decimals) to binary (multiply by 2 and collect "1", and "0" in 0th place).

    so to reiterate what i was saying:

    I know how to convert 2/3 to binary (mult by 2 and collect "1" and "0" in 0th place)

    however, the question is is there a way to convert 0.66666666666666666666666... (which is 2/3) to binary without converting it to fraction (2/3) first?

    TL;DR want to convert 0.666666666666666666666.... to binary without making use of the fact that it is 2/3
  5. Aug 28, 2014 #4


    User Avatar

    Staff: Mentor

    Show me how you convert 0.66666666 to binary by a method you know.
  6. Aug 28, 2014 #5
    When you ask "can you convert it to binary without rewriting X in fractional form", I have to assume you have ways of representing that repeating decimal and ways of working with repeating decimals in general. So this is not normal C programming, were repeating decimals are simply truncated to a limited precision.

    So here is what you do:
    Let R be your repeating decimal.
    Store the fractional part of R into R(0).
    Let n be 0.
    -- Store 2*R(n) into R.
    -- Store the fractional part of R into R(n+1).
    -- Store the non fractional part of R (a 0 or 1) to B(n). This will be your output.
    -- Let m be 0.
    -- Loop:
    -- -- If m is greater than n, break from this loop.
    -- -- If R(m) equals R(n+1), then:
    -- -- -- You are done.
    -- -- -- You have a repeating binary value from B(m) to B(n).
    -- -- -- Exit this procedure.
    -- -- Else
    -- -- Set m to m+1.
    -- End of Loop.
    -- Set n to n+1.
    End of Loop.

    The outer loop cannot exit. If there is a repeating decimal, there will be a repeating binary. If the decimal is not repeating, it will loop forever.
  7. Aug 28, 2014 #6
    Here's the [itex]0.\overline{6}[/itex] example:

    [itex]R=2\cdot R_{n} = 1.\overline{3}[/itex]
    [itex]R_{n+1} =[/itex] Fractional part of [itex]R = 0.\overline{3}[/itex]
    [itex]B_{n} =[/itex] Non Fractional part of [itex]R = 1[/itex]
    Compare [itex]B_{0} to B_{1}[/itex] Not equal
    [itex]R=2\cdot R_{n} = 0.\overline{6}[/itex]
    [itex]R_{n+1} =[/itex] Fractional part of [itex]R = 0.\overline{6}[/itex]
    [itex]B_{n} =[/itex] Non Fractional part of [itex]R = 0[/itex]
    Compare [itex]B_{0} to B_{2}[/itex] Equal, so we are done

    Answer is in array B and values n and m:
    [itex]B_{0} = 1[/itex]
    [itex]B_{1} = 0[/itex]
    [itex]m = 0[/itex]
    [itex]n = 1[/itex]
    So the overline will cross both digits of the binary value.
    It will look like this: [itex]0.\overline{10}[/itex].
    Last edited: Aug 28, 2014
  8. Aug 28, 2014 #7
    0.666666666... = 2/3

    2 * 2/3 = 4/3 = 1+1/3
    2 * 1/3 = 2/3 = 0+2/3
    2 * 2/3 = 1+ 1/3

    hence 0.66666666.... = 0.101010101010101010....

    now show me how to convert 0.666666.... to binary without converting it to fraction and thus making use of what i did above.

    i'm also not looking for a script either.

    i couldn't think of a way to do it hence why i'm curious if there is even a way.
  9. Aug 28, 2014 #8

    The Electrician

    User Avatar
    Gold Member

    the 1 becomes the first bit of the binary value which is .1xxxxxxx...--subtract the 1 and get:
    Now 2*.33333333333333333...
    the zero becomes the next bit of the binary value which is now .10xxxxxx...
    subtract the zero and get:
    Now 2*.66666666666666666...
    the 1 becomes the next bit of the binary value which is now .101xxxxxxx...

    et cetera.
  10. Aug 28, 2014 #9
    i'm not sure why i over-thought this problem so much lol. the was staring at the solution the entire time.

    thanks for doing that. cheers.
  11. Aug 29, 2014 #10


    User Avatar

    Staff: Mentor

    Keep multiplying it by 2. If the digit to the right of the decimal point is 5 or greater write 1, otherwise write 0.



    You can keep this up until you calculator display overflows.
  12. Aug 29, 2014 #11
    My method is a bit more complete because is provides a way of recognizing when you are done and what portion of the binary fraction is repeated.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted