在Java中从字符串转换为二进制字符串

时间:2013-12-27 13:03:30

标签: java binary

我有长度为80位的十六进制字符串,如“12345ABCDEF78E9CD741”,需要转换为二进制字符串。

我尝试了以下代码      String Skey =“12345ABCDEF78E9CD741”;      int i = Integer.parseInt(Skey,16);      String bin = Integer.toBinaryString(i);

但整数不能保持80位。那么如何在java中完成。

1 个答案:

答案 0 :(得分:1)

Parse it to a BigIntegerconvert that to binary

BigInteger bigint = new BigInteger("12345ABCDEF78E9CD741", 16);
System.out.println(bigint.toString(2));

输出:

  

10010001101000101101010111100110111101111011110001110100111001101011101000001