Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-2008, 10:54 PM
Member
 
Join Date: Dec 2007
Posts: 26
apfroggy0408 is on a distinguished road
Conversions
Hey guys having trouble with converting certain bases to other bases. I have a skeleton and some basic stuff written in but I'm getting run-time errors.

Code:
/** * @(#)Conversions.java * * * @author * @version 1.00 2008/2/26 */ public class Conversions { public static void main(String args[]) { //The next 2 lines are used in all versions. System.out.println("ABCD1234 Base-16 converts to " + BaseConverter.fromHexToBin("ABCD1234") +"in Base-2.\n"); System.out.println("E12B47F5 Base-16 converts to " + BaseConverter.fromHexToBin("E12B47F5") +"in Base-2.\n"); //The next 2 lines are used in the 90-point versions and above. System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToDec("1011111011101111") +"in Base-10.\n"); System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToDec("11100100100110110") +"in Base-10.\n"); //The next line is used in the 95-point versions and above. System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToHex("1011111011101111") + "in Base-16.\n"); //The next line is used in the 100-point versions and above. System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToHex("11100100100110110") + "in Base-16.\n"); //The next 3 lines are useed in the 105 and 110-point versions. System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,5) + "in Base-5.\n"); System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,8) + "in Base-8.\n"); System.out.println("200 Base-10 converts to " + BaseConverter.fromDecToAny(200,2) + "in Base-2.\n"); //This last line is only used in the 110 point version. System.out.println("48879 Base-10 converts to " + BaseConverter.fromDecToAny(48879,16) + "in Base-16.\n"); } } class BaseConverter { public static String fromHexToBin(String hexNum) { String binNum = ""; int h = Integer.parseInt("", 10); String es = Integer.toString(h, 10); int dd = Integer.parseInt(es, 2); System.out.println(es); return binNum; } public static int fromBinToDec(String binNum) { String decNum = ""; int i = Integer.parseInt("", 2); String s = Integer.toString(i, 2); System.out.println(s); int e = Integer.parseInt(s); return e; } public static String fromBinToHex(String binNum) { String hexNum = ""; //String s = 11; //s = hexNum.toString(16); // 120ff0 //if (s.length() % 2 != 0) { // s = "0"+s; return hexNum;} } public static String fromDecToAny(int decNum, int desiredBase) { String newNum = ""; return newNum; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-04-2008, 06:26 AM
Member
 
Join Date: Dec 2007
Posts: 26
apfroggy0408 is on a distinguished road
New updated code. Working 80 point version.

Code:
/** * @(#)Conversions.java * * * @author * @version 1.00 2008/2/26 */ public class Conversions { public static void main(String args[]) { //The next 2 lines are used in all versions. System.out.println("ABCD1234 Base-16 converts to " + BaseConverter.fromHexToBin("ABCD1234") +" in Base-2.\n"); System.out.println("E12B47F5 Base-16 converts to " + BaseConverter.fromHexToBin("E12B47F5") +" in Base-2.\n"); //The next 2 lines are used in the 90-point versions and above. System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToDec("1011111011101111") +" in Base-10.\n"); System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToDec("11100100100110110") +" in Base-10.\n"); //The next line is used in the 95-point versions and above. System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToHex("1011111011101111") + " in Base-16.\n"); //The next line is used in the 100-point versions and above. System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToHex("11100100100110110") + " in Base-16.\n"); //The next 3 lines are useed in the 105 and 110-point versions. System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,5) + " in Base-5.\n"); System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,8) + " in Base-8.\n"); System.out.println("200 Base-10 converts to " + BaseConverter.fromDecToAny(200,2) + " in Base-2.\n"); //This last line is only used in the 110 point version. System.out.println("48879 Base-10 converts to " + BaseConverter.fromDecToAny(48879,16) + " in Base-16.\n"); } } class BaseConverter { public static String fromHexToBin(String hexNum) { String binNum = ""; for (int j = 0 ; j<hexNum.length(); j++) switch (hexNum.charAt(j)) { 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; } 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; } }
Would like some help with the rest please
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 08:07 AM
Member
 
Join Date: Dec 2007
Posts: 26
apfroggy0408 is on a distinguished road
Code:
/** * @(#)Conversions.java * * * @author * @version 1.00 2008/2/26 */ public class Conversions { public static void main(String args[]) { //The next 2 lines are used in all versions. System.out.println("ABCD1234 Base-16 converts to " + BaseConverter.fromHexToBin("ABCD1234") +" in Base-2.\n"); System.out.println("E12B47F5 Base-16 converts to " + BaseConverter.fromHexToBin("E12B47F5") +" in Base-2.\n"); //The next 2 lines are used in the 90-point versions and above. System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToDec("1011111011101111") +" in Base-10.\n"); System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToDec("11100100100110110") +" in Base-10.\n"); //The next line is used in the 95-point versions and above. System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToHex("1011111011101111") + " in Base-16.\n"); //The next line is used in the 100-point versions and above. System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToHex("11100100100110110") + " in Base-16.\n"); //The next 3 lines are useed in the 105 and 110-point versions. System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,5) + " in Base-5.\n"); System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,8) + " in Base-8.\n"); System.out.println("200 Base-10 converts to " + BaseConverter.fromDecToAny(200,2) + " in Base-2.\n"); //This last line is only used in the 110 point version. System.out.println("48879 Base-10 converts to " + BaseConverter.fromDecToAny(48879,16) + " in Base-16.\n"); } } class BaseConverter { public static String fromHexToBin(String hexNum) { String binNum = ""; for (int j = 0 ; j<hexNum.length(); j++) switch (hexNum.charAt(j)) { 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; } return binNum; } public static int fromBinToDec(String binNum) { int decNum = 0; decNum = Integer.parseInt(binNum,2); return decNum; } public static String fromBinToHex(String binNum) { String hexNum = ""; hexNum = Integer.toHexString(Integer.parseInt(binNum, 2)); return hexNum; } public static String fromDecToAny(int decNum, int desiredBase) { String newNum = ""; //int i = Integer.parseInt(decNum, 10); // 1023 //newNum = Integer.toString(i, 10); return newNum; } }
Got 100 points now. Working on 105-110
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-05-2008, 01:59 AM
Member
 
Join Date: Mar 2008
Posts: 2
Zeroshade15 is on a distinguished road
ah very nice froggy. it seemed a lot more complicated than this..
+rep ahaha
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 04:51 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org