Thread: Base Converter Part 2

  1. #1
    Registered User
    Join Date
    Dec 2006

    Base Converter Part 2

    Hi guys, its me again. Just dropped by to say that I've managed to somehow visualize how my program is going to work. I actually have made a pseudocode (if you could call it one, haha) to guide me through the whole programming process. My problem is that I ain't quite sure if it really makes sense or if it points me to the right track. So I thought it might be a good idea to post it here and let you guys browse through it...Please please do take a quick look at it and comment on it. I would really appreciate it. Thank you guys and God bless!

    Outline for Base Converter Program

    Ask for input number; one place value at a time; range is from -268,435,455 to 268,435,455
    Ask for input base; range is from 2-16 only
    Ask for destination base; range is from 2-16 only
    An int variable is reserved for the input base, the destination base, as well as for each of the place values given; an int variable should also be assigned for each of the products in the proceeding step
    Each place value is multiplied with the base (w/c is raised to n; being dependent on the place value)
    The products from the preceding step (being already assigned to a variable) would now be used to convert from the present base (w/c is base 10) to the desired base of the user
    To do this, all the variables containing the products must first be assembled according to their place values (w/c I have no idea how to do it!)
    After doing so, the emerging number would then be divided continuously by the destination base, with each of the quotients assigned to another variable until a 1 or a 0 emerge as a divisor.
    If 1 remains, display 1 then followed by all the other quotients from the most recent to the first one to emerge
    If 0 remains, display answer starting from the most recent quotient up to the first one
    End the program

    ~~~Damn it ain't fun being a newbie!!! ^_^

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Sorry, my take. [Not necessarily great advice.]

    1. Take user input as a string.
    2. Convert the user input from a string to a value given the "from" base.
    3. Take the value and convert back to a string in the "to" base.
    The hard parts are steps 2 and 3, but the first part does have its issues.

    And yes, range verification is a very good idea. Just remember that you are working with an input of a string representation of a number in a certain base and "converting" to string representation of a number in another base.

    In the middle there is basic math.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    range is from -268,435,455 to 268,435,455
    That's an odd range. Why did you choose that? (I assume your values are in decimal. )

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  2. Base Converter
    By encyclopedia23 in forum C Programming
    Replies: 3
    Last Post: 12-29-2006, 08:55 AM
  3. loop with divition
    By cigcode in forum C Programming
    Replies: 6
    Last Post: 04-11-2004, 04:22 AM
  4. Number system base M, print numbers N digits wide...
    By biterman in forum C Programming
    Replies: 12
    Last Post: 11-19-2001, 04:31 AM
  5. converting numbers from one base to another
    By partnole in forum C++ Programming
    Replies: 4
    Last Post: 10-04-2001, 12:29 PM