Results 1 to 8 of 8
Thread: Number System Converter
 02152013, 12:57 PM #1Member
 Join Date
 Feb 2013
 Posts
 3
 Rep Power
 0
Number System Converter
Assignment Purpose:
This program requires knowledge of manipulation of Java String objects and methods. It also requires knowledge of Number System Conversions.
// Lab16MATH05st.java
// The Number System Converter
// This is the student, starting version of the Lab16MATH05 assignment.
import java.util.Scanner;
public class Lab16MATH05st
{
public static void main (String args[])
{
System.out.println("Lab16MATH05  Number Conversion Program\n\n");
// The next 2 lines are used in all versions.
System.out.println("ABCD1234 Base16 converts to " + BaseConverter.fromHexToBin("ABCD1234") + " in Base2.\n");
System.out.println("E12B47F5 Base16 converts to " + BaseConverter.fromHexToBin("E12B47F5") + " in Base2.\n");
// The next 2 lines are used in the 90point versions and above.
// System.out.println("1011111011101111 Base2 converts to " + BaseConverter.fromBinToDec("1011111011101111") + " in Base10.\n");
// System.out.println("11100100100110110 Base2 converts to " + BaseConverter.fromBinToDec("11100100100110110") + " in Base10.\n");
// The next line is used in the 95point versions and above.
// System.out.println("1011111011101111 Base2 converts to " + BaseConverter.fromBinToHex("1011111011101111") + " in Base16.\n");
// The next line is used in the 100point versions and above.
// System.out.println("11100100100110110 Base2 converts to " + BaseConverter.fromBinToHex("11100100100110110") + " in Base16.\n");
// The next 3 lines are used in the 105 and 110point versions.
// System.out.println("1000 Base10 converts to " + BaseConverter.fromDecToAny(1000,5) + " in Base5.\n");
// System.out.println("1000 Base10 converts to " + BaseConverter.fromDecToAny(1000,8) + " in Base8.\n");
// System.out.println("200 Base10 converts to " + BaseConverter.fromDecToAny(200,2) + " in Base2.\n");
// This last line is only used in the 110 point version.
// System.out.println("48879 Base10 converts to " + BaseConverter.fromDecToAny(48879,16) + " in Base16.\n");
}
}
class BaseConverter
{
public static String fromHexToBin(String hexNum)
{
String binNum = "";
return binNum;
}
public static int fromBinToDec(String binNum)
{
int decNum = 0;
return decNum;
}
public static String fromBinToHex(String binNum)
{
String hexNum = "";
return hexNum;
}
public static String fromDecToAny(int decNum, int desiredBase)
{
String newNum = "";
return newNum;
}
}
90Point Version Specifics
The 90point version requires that you write both the fromHexToBin and fromBinToDec methods.
90Point Version Output
95Point Version Specifics
The 95point version requires everything from the 90point version and adds the fromBinToHex method. For this version, you may assume that the binary number will have a multiple of 4 bits.
95Point Version Output
100Point Version Specifics
The 100point version requires the same methods as the 95point version; however, the fromBinToHex method needs to be improved so it can convert regardless of the number of bits.
100Point Version Output
105Point Version Specifics
The 105point version requires everything from the 100point version and adds the fromDecToAny method. For this version, the method needs to be able to convert from decimal to any base between 2 and 10. Base 16 is not required for this version.
105Point Version Output
110Point Version Specifics
The 110point version requires the same methods as the 105point version; however, the fromDecToAny method needs to be improved so it can also convert to base16.
 02152013, 01:00 PM #2Member
 Join Date
 Feb 2013
 Posts
 3
 Rep Power
 0
Re: Number System Converter
Code so far: I have to fix my loop, i get 7 errors
public static String fromHexToBin(String hexNum)
{
String binNum = " " ;
for (int k = 0; k < hexNum.length()0; k++)
{
switch (hexNum,charAt(k))
{
case '0' : binNum += "0000" ; break;
case '1' : binNum += "0001" ; break;
case '2' : binNum += "0010" ; break;
case '3' : binNum += "0011" ; break;
case '4' : binNum += "0100" ; break;
case '5' : binNum += "0101" ; break;
case '6' : binNum += "0110" ; break;
case '7' : binNum += "0111" ; break;
case '8' : binNum += "1000" ; break;
case '9' : binNum += "1001" ; break;
case 'A' : binNum += "1010" ; break;
case 'B' : binNum += "1011" ; break;
case 'C' : binNum += "1100" ; break;
case 'D' : binNum += "1101" ; break;
case 'E' : binNum += "1110" ; break;
case 'F' : binNum += "1111" ; break;
}
}
 02152013, 01:38 PM #3
Re: Number System Converter
Please use the [code] [/code] tags when posting code and always include the errors you get. YSou might also want to follow the link in my signature to get more information.
Math problems? Call 1800[(10x)(13i)^2][sin(xy)/2.362x]
The Ubiquitous Newbie Tips
 02152013, 07:18 PM #4Senior Member
 Join Date
 Oct 2010
 Posts
 393
 Rep Power
 5
Re: Number System Converter
Hi SneakerIntel, welcome to the forums.
Straight off I can see two mistakes from the code above. There is no return statement and your method call within your switch statement uses a comma instead of a full stop.
What error codes are you seeing, this does allow people to fault find as opposed to just guessing.
Regards.
 02152013, 11:49 PM #5Member
 Join Date
 Feb 2013
 Posts
 3
 Rep Power
 0
Re: Number System Converter
Ronin thank you very much. I fixed my code i am at the 90, Does anyone have any insight as to how to code the 110 point?
Last edited by SneakerIntel; 02162013 at 07:11 PM.
 02072014, 03:33 AM #6Member
 Join Date
 Feb 2014
 Posts
 3
 Rep Power
 0
Re: Number System Converter
i have the same lab but im stuck at 80 point. i got this output
Lab16MATH05  Number Conversion Program
ABCD1234 Base16 converts to 1010 in Base2.
E12B47F5 Base16 converts to 1110 in Base2.
Process completed.
 02072014, 05:02 AM #7▼ dafuq did I do?
 Join Date
 Dec 2013
 Posts
 204
 Rep Power
 0
Re: Number System Converter
Well, I have a question for you, does this conversion have to be manual?, because there are default java methods that will do this for you.
1000011 1100001 1101110 100000 1111001 1101111 1110101 100000 1110010 1100101 1100001 1100100 100000 1000010 1101001 1101110 1100001 1110010 1111001 111111
 02072014, 08:15 PM #8Member
 Join Date
 Feb 2014
 Posts
 3
 Rep Power
 0
Similar Threads

converter
By fasooly1992 in forum New To JavaReplies: 2Last Post: 12252012, 09:54 PM 
converting a given positive integer m to a positional number system in base n
By Renxx in forum New To JavaReplies: 2Last Post: 11272011, 06:11 PM 
counting number of lines of system.out
By IYIaster in forum New To JavaReplies: 1Last Post: 07212009, 12:37 AM 
Prime Number  System print all the prime numbers ...
By pinkdreammsss in forum New To JavaReplies: 20Last Post: 04262009, 01:50 AM 
Auto generated number system?
By javanewbie in forum New To JavaReplies: 2Last Post: 08092008, 05:16 AM
Bookmarks