Converting BigInteger to binary string

Kailash picture Kailash · Dec 24, 2013 · Viewed 21.7k times · Source

Can we convert Biginteger to binary string

   String s1 = "0011111111101111111111111100101101111100110000001011111000010100";
   String s2 = "0011111111100000110011001100110011001100110011001100110011001100";
   BigInteger bi1, bi2, bi3;
   bi1 = new BigInteger(s1,2);
   bi2 = new BigInteger(s2,2);
   bi3 = bi1.xor(bi2);

How to convert bi3 to binary string

Answer

Sergey Kalinichenko picture Sergey Kalinichenko · Dec 24, 2013

You can use toString(radix) for that:

String s3 = bi3.toString(2);