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
Post a Comment