java - How to convert 160 digit binary string to 20 byte array? -


i have binary string containing 160 digit. have tried:

new biginteger("0000000000000000000000000000000000000000000000010000000000000000000000000000001000000000010000011010000000000000000000000000000000000000000000000000000000000000", 2).tobytearray() 

but returns 15 bytes array removed leading 0 bytes.

i reserve leading 0 bytes, keep 20 bytes.

i know other ways accomplish that, know there easier way might need few lines of code.

why not simply:

public static byte[] convert160bitstobytes(string binstr) {     byte[] = new biginteger(binstr, 2).tobytearray();     byte[] b = new byte[20];     int = 20 - a.length;     int j = 0;     if (i < 0) throw new illegalargumentexception("string long");     (; j < a.length; j++,i++) {         b[i] = a[j];     }     return b; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -