How to convert binary string to binary byte array in Java -


i have binary string this: string = "100100". need have binary byte array: byte[] b = {1,0,0,1,0,0} output.

this code:

    string a="100100";      byte[] b = null;     (int = 0; < a.length(); i++) {         b[i]=a.charat(i)=='1'? (byte) 1: (byte) 0;         system.out.println("b["+i+"]: "+b[i]);     } 

but approach not working when run it. can 1 give correction? thank you

byte[] not initialized. need initialize before use .

byte[] b = new byte[a.length()];  try 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -