我想将字符串9C72E0FA11C2E6A8转换为十进制值:
String strHexNumber = "9C72E0FA11C2E6A8"; Long decimalNumber = Long.parseLong(strHexNumber, 16); System.out.println("Hexadecimal number converted to decimal number"); System.out.println("Decimal number is : " + decimalNumber);
我期待获得价值11273320181906204328
,但我得到了
Exception in thread "main" java.lang.NumberFormatException: For input string: "9C72E0FA11C2E6A8" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:592) at ConvertHexToDecimalExample.main(ConvertHexToDecimalExample.java:22)
如何在Java中将十六进制转换为十进制?
谢谢!
使用BigInteger 传递String值作为参数,并将radix作为参数
String strHexNumber = "9C72E0FA11C2E6A8"; BigInteger mySuperBigInteger = new BigInteger(strHexNumber , 16);