I am trying to print the result of a bit string to hex string conversion but it prints nothing. In other words 000110011101 should print "19d" are my temp variables the issue?
Thanks in advance for any assistance, this is my code:
public static void BinaryToHex() {
Scanner scanner = new Scanner(System.in);
String bitString = "";
String hexString = "";
String[] hex = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C",
"D", "E", "F" };
String[] binary = { "0000", "0001", "0010", "0011", "0100", "0101", "0110",
"0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" };
System.out.println("Enter a bit string: ");
bitString = scanner.next();
for (int i = 0; i < bitString.length(); i++) {
char temp = bitString.charAt(i);
String temp2 = "" + temp + "";
for (int j = 0; j < binary.length; j++) {
if (temp2.equalsIgnoreCase(binary[j])) {
hexString = hexString + hex[j];
}
}
}
System.out.print("The equivalent hex string is ");
System.out.println(hexString);
}