Results 1 to 5 of 5
 01242015, 10:34 PM #1Member
 Join Date
 Jan 2015
 Posts
 2
 Rep Power
 0
Having problem with base converting program
Before I begin, I need to confess that this is indeed, for an assignment for class. However, I have worked quote hard on it, only to hit a brick wall.
The idea behind this program is that the program prompts the user to input an initial base (236), which checks to ensure that it is a valid int, then asks for a number to convert (which is taken as a String), then it asks which desired base the user would like to convert said number to. I have a basic program that is not complete, but allows me to do a few conversions using convertTo. I believe that I am going to have abandon this method and try mathematically converting every number. This leads me to what I can and cannot do. I am unable to use the initialBase as a condition to know what kind of number i an converting. For instance, I don't know how to make program know that if "2" is the initialBase, that that means that the String is a binary number. THAT is what I'm having problems with.
Here is my initial program that has a few things that are copied and pasted from other bits of my code in my program:
XML Code:http://pastebin.com/6uu9pq7S
 Check to see if the input base is 2, 8, 10, 16, or 32. Hint: Put the possible bases in an array, and check the input base against the array.
 Check to see if the input number is valid for the base. Hint: Create a String "0123456789ABC...V" and compare each input character with the first "base" characters of the String.
 Check to see if the output base is 2, 8, 10, 16, or 32. Hint: Use the same possible bases array you used in step 1 to verify the input base.
 Check to see if the input base is equal to the output base. If so, print the input number.
 Perform a conversion from the input base to base 10.
 Perform a conversion from base 10 to the output base. You do this in 2 steps because it's easier to check each conversion separately.
 Output the converted number.
 01242015, 11:26 PM #2
Re: Having problem with base converting program
What have you tried?
if "2" is the initialBase, that that means that the String is a binary number. THAT is what I'm having problems with.If you don't understand my response, don't ignore it, ask a question.
 01242015, 11:36 PM #3Member
 Join Date
 Jan 2015
 Posts
 2
 Rep Power
 0
Re: Having problem with base converting program
Here is an example of what I need"
"Enter a number to convert: "
*user enters number
"Enter what the base is of this number: "
*user enters what base format the number is*
"Now enter what base you'd like to convert this number to: "
*user enters what base to convert number to*
(conversion takes place behind the scenes)
Converted number is printed
What I am having problems with is how to make the program aware what base I am using initially. I can create a program where you enter a specific number in a require base (like hex) and have it convert it into say binary, but I don't know how to let the program know that something is initially a certain base and it know how to convert it to whatever provided finalBase is required.
 01252015, 12:53 AM #4Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
Re: Having problem with base converting program
Well you prompt for the input base and then the number, and then the output base. So let's assume you want to convert hex to binary.
prompt for input base: 16
input number: C7 (you also need to check that it conforms to base).
output base: 2
output number would be 11000111
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 01252015, 09:10 AM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Re: Having problem with base converting program
Basically, you need to convert a String to an int (given a certain radix) and you need to convert from an int to a String (given (another) radix). If you setup your code like this:
Java Code:int convertFrom(String input, int radix) { ... } String convertTo(int number, int radix) { ... }
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads

Problem with mbrola.base
By arshadalisoomro in forum Advanced JavaReplies: 26Last Post: 07152012, 08:47 PM 
Help with converting to base 10 program
By jsoeung in forum New To JavaReplies: 2Last Post: 04232012, 01:20 PM 
Converting Number to Base 8
By nighteagle2 in forum New To JavaReplies: 9Last Post: 02172012, 02:38 AM 
converting a given positive integer m to a positional number system in base n
By Renxx in forum New To JavaReplies: 2Last Post: 11272011, 05:11 PM 
A Number Converting Program!
By WastedxYears in forum New To JavaReplies: 2Last Post: 01092010, 12:47 AM
Bookmarks