I Have run into a brickwall and I'm not sure how to continue.
Quick Rundown: My code is suppose to turn 4 Strings of Hexadecimals(ramError1-4) to Binary, manually. I Want to be able to loop 4 times and each time create a unique StringBuilder to continue to the next step.
I have tried over and over again the past two days to get it to work without success. Any advice would be appreciated. This is my code without my failed loops. Hex2 works as a test, but I want to be able to loop through HexCodes 1-4(ramError1-4)
So how do I loop through Hex1-4 while creating a StringBuilder?
Note: ramErrors1-4 do have strings in them I added earlier in the code by reading a file.
String Hex1=ramError1;
String Hex2=ramError2;
String Hex3=ramError3;
String Hex4=ramError4;
StringBuilder hexstring1 = new StringBuilder();
StringBuilder hexstring2 = new StringBuilder();
StringBuilder hexstring3 = new StringBuilder();
StringBuilder hexstring4 = new StringBuilder();
for (int x = 0; x <= 8; x++)
{
if (Hex2.charAt(x) == 'A')
{
hexstring1.append("1010");
}
else if (Hex2.charAt(x) == 'B')
{
hexstring1.append("1011");
}
else if (Hex2.charAt(x) == 'C')
{
hexstring1.append("1100");
}
else if (Hex2.charAt(x) == 'D')
{
hexstring1.append("1101");
}
else if (Hex2.charAt(x) == 'E')
{
hexstring1.append("1110");
}
else if (Hex2.charAt(x) == 'F')
{
hexstring1.append("1111");
}
else if (Hex2.charAt(x) == '0')
{
hexstring1.append("0000");
}
else if (Hex2.charAt(x) == '1')
{
hexstring1.append("0001");
}
else if (Hex2.charAt(x) == '2')
{
hexstring1.append("0010");
}
else if (Hex2.charAt(x) == '3')
{
hexstring1.append("0011");
}
else if (Hex2.charAt(x) == '4')
{
hexstring1.append("0100");
}
else if (Hex2.charAt(x) == '5')
{
hexstring1.append("0101");
}
else if (Hex2.charAt(x) == '6')
{
hexstring1.append("0110");
}
else if (Hex2.charAt(x) == '7')
{
hexstring1.append("0111");
}
else if (Hex2.charAt(x) == '8')
{
hexstring1.append("1000");
}
else if (Hex2.charAt(x) == '9')
{
hexstring1.append("1001");
}
else
{
System.out.println("error at char" + x );
}
}
System.out.println("Hex To Binary is " + hexstring1.toString());
System.out.println("Hex To Binary is " + hexstring2.toString());
System.out.println("Hex To Binary is " + hexstring3.toString());
System.out.println("Hex To Binary is " + hexstring4.toString());
vmina 3994433
consider having a String array for the
Hex
then move your
for loop
to a new methodThis can then be called