Thread: Base Conversion

  1. #1

    Question Base Conversion

    I need to code an algorithm that will conver any number in any base 2 thru 9 and output the number to its base 10 equivalent....
    in order to do so, i have to figure out a way to analyze each digit of the number that the user inputs. i cant figure this a matter of fact i cant figure any of this algorithm out. i have an idea of how to convert numbers back and forth in their baes but i dont know how to code that. could someone please please help me?!?! i am new to programming and having a rough time, there are no tutors at my school..Thank you!

  2. #2
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    1. Retreive the user output into a character array, where all the values are (hopefully) numbers.

    2. Scan through the array using a while loop (end condition null zero detection) to find how many digits it contains.

    3. Scan backwards through the array (right to left), multiplying each digit value (converted from ASCII code to actual number) by the base raised to the power of the position index and add the result to a running total which (when the scan is done) will contain your base-10 result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. base 10 to base 2 conversion
    By dteum in forum C++ Programming
    Replies: 4
    Last Post: 09-27-2008, 01:12 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM