I have a large binary string "101101110...", and I am trying to store it into a byte array. what is the best way of doing it?
Lets say I have largeString = "0100111010111011011000000001000110101"
Result that I'm looking for:
[78, 187, 96, 17, 21]
01001110 10111011 01100000 00010001 10101
What i've tried:
byte[] b= new BigInteger(largeString,2).toByteArray();
however it did not give me the result I'm looking for...
Assuming that your binary string module 8 equals 0
binString.lenght()%8==0
You can easily build an ArrayList on which you can call toArray if you want an actual array;
Do it in a loop. Split the string at 8-character chunks and convert them separately. In "pseudocode" it's something like: