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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -