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

Number and base

  1. Sep 27, 2011 #1
    Hey guys so I have to make a code for my class that you input a number..then you input the base..and it will print the decimal representation

    I havent seen this in math so I am a bit confused, just wanted to know what this was called so I can read up on a tutorial.

  2. jcsd
  3. Sep 28, 2011 #2

    You have to run the Applet.
  4. Sep 28, 2011 #3
    I just found video on khanacademy.. Relieved hehe..where I am a bit confused is: what is the limit on bases?? 1 2 4 8 16..is there more??
  5. Sep 28, 2011 #4
    A base is just a way of counting. You could go up to base 1000000 if you want - or more. Any value will do.
    In fact, there is a number called "e" which is an irrational value like pi, that is approximately 2.71828, that crops up very, very often in seemingly unrelated maths all throughout the field. The base of e is an extremely useful base, particularly when you reach exponential functions in calculus.
  6. Sep 28, 2011 #5
    would it be logical to assume the following:
    since the remainder of n/2 [until x^0]
    can be used to get binary code
    6 3 0
    3 1 1
    1 0 1


    can I assume this for all bases?

  7. Sep 28, 2011 #6

    (assuming integer divide that truncates the number)

    For 6 from base 10 to base 2:

    6%2 = 0, 6/2 = 3
    3%2 = 1, 3/2 = 1
    1%2 = 1, 1/2 = 0

    You stop at zero on the second and the list of numbers reversed is the binary: 110

    Just like you did.

    This works for all integer bases:

    For 47 from base 10 to base 16 (using A-F for 10-15):

    47%16 = 15, 47/16 = 2
    2%16 = 2, 2/16 = 0

    Hex: 2F

    If you want a higher base, you have to have something to represent it, or you just put a comma between numbers like (2,15) instead of 2F or 0x2F

    I guess you could call it decimal to other base conversion. To convert back is a little more complicated. You can do the same in that base (which can be confusing if you don't have a table), but it's easier to represent each numeral by the power representation of the base in that location and add it up to convert back, because you can do that in decimal.

    Oh, like Kael42 said. Base can really be anything. You may want to stick to positive integer bases that are 2 are larger (2,3,4,5,...) until you get an idea how it works first. Well, you can do unary also, but then you'll have a lot of 1's across the screen.
    Last edited: Sep 28, 2011
  8. Oct 1, 2011 #7
    Yet another approach to go from base 10 to base n:

    Let x be written in base 10, to be written in base n:

    i) Find the largest integer power a_1 of n that is smaller than x, i.e., n^a_1< x, but
    n^(a_1+1)>x . Find the quotient q_1 of x by n^a1

    ii) Find the largest integer power a_2 of n that is smaller than x-(n^a_1)
    Again, find the quotient q_2 of x-q_1(n^a_1) by n^a2

    iii) In the last step, you either get a multiple of n, then set q_k=0 , or you get
    some number y smaller than n (this means x-(n^a_1-n^a_2-... n^a_(k-1) <n ), then set

    iv) Your number in base n is q_1q_2....q_k.

    Example: 1670 in base 7:

    i) Largest power of 7 smaller than 1670 is 343 . The quotient of 1670 by 343 is 4,
    so q_1:=4

    ii) Largest power of 7 smaller than (1670-4(343)=298) is, now 49, and the quotient
    of 298 by 49 is 6 , so q_2:=6

    iii) since q_2=4<7, declare q_4:= 4.

    Then 1670 in base 7 is 4604 ; (4604)_7 = 4.7^0+ 0.7^1+ 6.7^2+ 4.7^3 =

    4.1+0.7+ 6.49+ 4.343 = 4+0+ 294+ 1372.

    So, basically, you recursively substract the multiple of the largest power of the base that is larger than zero , until you get something smaller than n.
    Last edited: Oct 1, 2011
  9. Oct 1, 2011 #8


    User Avatar
    Staff Emeritus
    Science Advisor

    Any positive integer can be a base (actually any positive number can but fractional bases are too complicated!). Also, if your base is larger than 10 you are going to need more symbols for "digits" greater than 9. Simplest is to use letters- A= 10, B= 11, etc.
  10. Oct 6, 2011 #9
    I totally wrote a program like this with Qt, it converted to a ton of bases, from negasexagesimal to phinary, quater-imaginary, balanced ternary to sexigasmal..

    Here: http://neuraloutlet.wordpress.com/projects/ [Broken]

    You just need to have a good read through here: http://en.wikipedia.org/wiki/Numeral_system
    Last edited by a moderator: May 5, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Number and base
  1. Number Base Comparisons (Replies: 34)