I have a small error in my code that I cannot for the life I figured out.
I have an array of strings representing binary data (after converting from hex), for example: one index is 1011, the other is 11100. I scan the array and put each index at 0 so that each index is eight bytes. When I try to convert these views to actual bytes, I get an error message when I try to parse the '11111111' The error I get:
java.lang.NumberFormatException: Value out of range. Value:"11111111" Radix:2
Here is a snippet:
String source = a.get("image block"); int val; byte imageData[] = new byte[source.length()/2]; try { f.createNewFile(); FileOutputStream output = new FileOutputStream(f); for (int i=0; i<source.length(); i+=2) { val = Integer.parseInt(source.substring(i, i+2), 16); String temp = Integer.toBinaryString(val); while (temp.length() != 8) { temp = "0" + temp; } imageData[i/2] = Byte.parseByte(temp, 2); }
source share