我无法将Hex转换为BigInteger

时间:2021-11-07 16:51:50

I tried to convert Hex to BigInteger, here is source code:

我试图将Hex转换为BigInteger,这里是源代码:

public static void main (String[] args)
{
    BigInteger a = new BigInteger("c6e87a3b3ef791287ac85a0c7836dd8305dd9a4c0024123db9145bb5067a8abf142e9001b0788039fd4d676b59db2110da23532282c7648d94fdbf29b731b0d21f9ca51acd44063f271326915283af97f0822519bbe2a6b80618e45e6194b2445d5afe70cf2c10569034966f3bc3b9a30d3ac4f06dbbca89fce7ef64ee14de3dL", 16);
    BigInteger b = new BigInteger("9e5d1bd4f53eebc8a695c61ba4436e38af273fd6733115611fded8dd407b5f0bc04301829dc6ed921af866c3c7977839fc75831152307f8e50e3c0f9107b6ae82ddab584807ea5ba7f32f9bfcab6218c6c6367817dfdd3b2ccc5c21cc9550b9248cac34dfb0d22151c196ca843f15614b3f6b044f9c5e727dc0b44f441c2ed7fL", 16);
    System.out.println(a);
    System.out.println(b);
    // System.out.println(modInv(a, b));
}

I tried to run this source code, but I got Runtime error like this:

我试着运行这个源代码,但是我得到了运行时错误,如下所示:

Exception in thread "main" java.lang.NumberFormatException: For input string: "....14de3dL" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.math.BigInteger.(Unknown Source) at sss.main.main(main.java:15)

线程“main”中的异常java.lang.NumberFormatException:对于java的java.lang.Integer.parseInt(Unknown Source)中java.lang.NumberFormatException.forInputString(Unknown Source)的输入字符串:“.... 14de3dL”。在sss.main.main(main.java:15)的math.BigInteger。(未知来源)

Is there something problem in source code? I can't find it.

源代码中有问题吗?我找不到它。

2 个解决方案

#1


0  

As pointed out in comment L is not part of Hexadecimal presentation.L is used to represent the string as Long, so it is an invalid character in the hexadecimal presentation. Code below should be helpful

正如注释中所指出的,L不是十六进制表示的一部分.L用于将字符串表示为Long,因此它是十六进制表示中的无效字符。以下代码应该会有所帮助

 BigInteger a = new BigInteger("c6e87a3b3ef791287ac85a0c7836dd8305dd9a4c0024123db9145bb5067a8abf142e9001b0788039fd4d676b59db2110da23532282c7648d94fdbf29b731b0d21f9ca51acd44063f271326915283af97f0822519bbe2a6b80618e45e6194b2445d5afe70cf2c10569034966f3bc3b9a30d3ac4f06dbbca89fce7ef64ee14de3d", 16);
 System.out.println(a.toString());

#2


1  

First of All, L is not included in Hex Numbers that you wrote in the end of both strings. you can visit this link for help on Hex Numbers

首先,L不包括在两个字符串末尾写的十六进制数字中。您可以访问此链接以获取有关Hex Numbers的帮助

https://en.wikipedia.org/wiki/Hexadecimal

After visiting this , please view this post as well

访问此内容后,请查看此帖子

Java convert a HEX String to a BigInt

Java将HEX String转换为BigInt

#1


0  

As pointed out in comment L is not part of Hexadecimal presentation.L is used to represent the string as Long, so it is an invalid character in the hexadecimal presentation. Code below should be helpful

正如注释中所指出的,L不是十六进制表示的一部分.L用于将字符串表示为Long,因此它是十六进制表示中的无效字符。以下代码应该会有所帮助

 BigInteger a = new BigInteger("c6e87a3b3ef791287ac85a0c7836dd8305dd9a4c0024123db9145bb5067a8abf142e9001b0788039fd4d676b59db2110da23532282c7648d94fdbf29b731b0d21f9ca51acd44063f271326915283af97f0822519bbe2a6b80618e45e6194b2445d5afe70cf2c10569034966f3bc3b9a30d3ac4f06dbbca89fce7ef64ee14de3d", 16);
 System.out.println(a.toString());

#2


1  

First of All, L is not included in Hex Numbers that you wrote in the end of both strings. you can visit this link for help on Hex Numbers

首先,L不包括在两个字符串末尾写的十六进制数字中。您可以访问此链接以获取有关Hex Numbers的帮助

https://en.wikipedia.org/wiki/Hexadecimal

After visiting this , please view this post as well

访问此内容后,请查看此帖子

Java convert a HEX String to a BigInt

Java将HEX String转换为BigInt