Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Converting between bases

  1. Jun 26, 2015 #1
    I can most of the time successfully convert between base 10 and another base or another base and base 10 or between 2 bases where one of them is a power of the other(like base 2 and base 4 or base 3 and base 9).

    With negative bases I sometimes don't get what I want in that negative base and with fractional bases there are 2 expansions for every rational number greater than or equal to 1, They are an infinite sequence of digits to the left and a terminating or repeating decimal to the right. But how will I know if it is a repeating decimal and what repeats in that repeating decimal?

    Like what if I wanted to represent 2/3 in base 1/2?

    Also I don't know of an easy way to convert between 2 bases that are not powers of each other or base 10 and another base.

    Here is how I convert between base 10 and another base:

    1) ##log_n(x) = y## Here n is the base I want to convert to and x is the base 10 number I want to convert.

    2) ##y =## some irrational number ##y' =## Just the integer and not the whole irrational

    3) ##\frac{x}{n^{y'}}##

    4) Write down the integer part(which is equal to ##z##) as the digit in the ##n^{y'}## place

    5) ##z*n^{y'}##

    6)##x-(z*n^{y'})##

    7) repeat until you reach the ##n^0## place

    8) If needed extend it to decimals in base ##n##.

    When I convert between 2 bases that are powers of each other I start from the right and make n groups of ##log_x(y)## digits where ##x## is the current base and ##y## is a power of that base. I then take those groups as if they were individual numbers themselves, add up their values and write down their values from right to left

    But how can I convert directly between 1 base and another base when it is neither one of these 2 previous scenarios like for example converting directly from base 2 to base 3?
     
  2. jcsd
  3. Jun 26, 2015 #2
    If you want to convert a positive integer from base 10 to base b (b integer greater than 1), you can do it by successive euclidean divisions :

    ## n = b q_0 + r_0 ##
    ## q_0 = b q_1 + r_1 ##
    ...
    ## q_{k-1} = b q_k + r_k ##
    ...
    until the quotient is 0.
    In the end, ##n = \sum_{k=0}^m r_k b^k ##. So, collecting the remainders gives you the conversion from base 10 to b : ##(n)_b = (r_m....r_0)##

    If you want to convert from base b to c, the only option I know (and I don't know much), you can go from base b to 10 and from base 10 to c.

    Assume that you now you have a positive real number in base 10 with fractional part x, and you want to convert x to base b, so that ## x = \sum_{k=1}^p s_k b^{-k} ##. An algorithm that gives you the ##s_k## is :

    ## s_1 = \lfloor bx \rfloor, x \leftarrow bx - s_1 ##
    ...
    ## s_k = \lfloor b x\rfloor, x \leftarrow bx - s_k ##
    until ##x=0##

    But I have the feeling you already know that, and probably better than me :confused:
     
  4. Jun 28, 2015 #3

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    For the specific case "write 2/3 in base 1/2", start by noting that 2/3 is larger than 1/2. But 2/3- 1/2= 1/6 which is less than 1/2 so the first "digit" right of the "decimal" point is 1: it starts "0.1...". Now note that (1/2)^2= 1/4 is larger than 1/6. The next place is 0: we have "0.10...". (1/2)^3= 1/8 is less than 1/6 and 1/6- 1/8= 2/48= 1/24 is less than 1/2: now we have "0.101...". (1/2)^4= 1/16 is larger than 1/24 so the next place is 0: "0.1010...". Continue like that. Of course, this will be a non-terminating "decimal".

    (I put words like "digit" and "decimal" in quotes because those names are, of course, derived from the Greek "deci" for one-tenth and don't really apply to other bases.)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Converting between bases
  1. Online converters (Replies: 3)

  2. Base 10 and Base b (Replies: 1)

  3. Base 10? (Replies: 39)

Loading...