Just look at lower part now
I've seen on here before ways to convert hex to binary, but my question is: is it possible to convert hex values inside of a byte array into binary values and put it into a big string?
The code I've been working on so far is:
public static void main (String[] args){
byte [] ex;
ex = new byte [] {(byte)0xFF, (byte)0x11, (byte)0xEE, (byte)0x22, (byte)0xDD, (byte)0x33, (byte)0xCC, (byte)0x44};
printByteArray(ex);
}
public static void printByteArray(byte [] array)
{
System.out.print("[ ");
for(int i = 0; i < array.length; i++)
{
System.out.print(Integer.toHexString((array[i]>>4)&0x0F).toUpperCase());
System.out.print(Integer.toHexString(array[i]&0x0F).toUpperCase() + " ");
}
System.out.println( "]");
}
What I want is to change is to be able to put the whole binary string into a byte array, i.e., to get the binary values for each hex number and then put it all into on HUGE byte array.
EDITED
Okay well I'm going with the first one it doesn't matter all that much I guess how long they are, they were still correct. But now could you just help me take and use that string. I have this code :
public static void main (String[] args){
String binary;
byte [] ex;
ex = new byte [] {(byte)0xFF, (byte)0x11, (byte)0xEE, (byte)0x22, (byte)0xDD, (byte)0x33, (byte)0xCC, (byte)0x44};
printByteArray(ex);
binary = hexToBin(ex);
System.out.println(binary);
}
public static String hexToBin(byte [] array)
{
String binStr = null;
for(int i = 0; i < array.length; i++){
binStr.append(Integer.toBinaryString(array[i]));
}
return binStr;
}
... but due to the fact of how I initialized the string (at first) my output has null in it. Any ideas how to fix that? Also I just changed it to append and now I don't know why but won't let me use it?