NumericConversion.java - import java.util public class...

This preview shows page 1 - 3 out of 4 pages.

import java.util.*; public class NumericConversion { public static String reverseString(String stringToBeReversed) { String reversedString = ""; for(int i = stringToBeReversed.length() - 1; i >= 0; i--) { reversedString = reversedString.concat(String.valueOf(stringToBeReversed.charAt(i)).toUpperCase() ); } return reversedString; } public static short hexCharDecode(char digit) { String value = String.valueOf(digit).toUpperCase(); short num = 0; switch (value) { case "A": num = 10; break; case "B": num = 11; break; case "C": num = 12; break; case "D": num = 13; break; case "E": num = 14; break; case "F": num = 15; break; default: num = Short.parseShort(value); break; } return num; } public static long hexStringDecode(String hex) { // convert from hexadecimal to decimal // if it begins with 0x or 0b, remove it if ((hex.indexOf("0x") == 0) || (hex.indexOf("0b") == 0)) { hex = hex.substring(2); } long num = 0; String value; String reversedHex = ""; // reverse hex reversedHex = reverseString(hex); // get value of each character in hex string for (int i = 0; i < reversedHex.length(); i++) { value = String.valueOf(reversedHex.charAt(i)); switch (value) { case "A": num += 10 * Math.pow(16, i);
break;

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture