我尝试使用以下代码将包含64位的二进制字符串转换为十六进制:
String mm = "1000010111101000000100110101010000001111000010101011010000000101";
String v = new BigInteger(mm, 2).toString(16);
v=String.format("%64x", v);
但它给了我这个例外:
Exception in thread "main" java.util.IllegalFormatConversionException: x != java.lang.String
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at test.main(test.java:332)
出了什么问题,为什么?
答案 0 :(得分:3)
改变这一点:
v=String.format("%64x", v);
到此:
v=String.format("%s", v);
你还需要这个:
String v = new BigInteger(mm, 2).toString(16);