I have binary string like this: String a = "100100". I need to have binary byte array: byte[] b = {1,0,0,1,0,0} for output.
This is my code:
String a="100100";
byte[] b = null;
for (int i = 0; i < a.length(); i++) {
b[i]=a.charAt(i)=='1'? (byte) 1: (byte) 0;
System.out.println("b["+i+"]: "+b[i]);
}
But this approach is not working when i run it. Can any one give a correction? Thank you