Java 将十六进制字符串转换为 BigInt
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4316645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java convert a HEX String to a BigInt
提问by user524156
Hi am trying to convert a hex string such as String hexStr = "1b0ee1e3"; to a bigInt, ideally i'd like to convert hexStr to a bigint in its decimal form,
嗨,我正在尝试转换十六进制字符串,例如 String hexStr = "1b0ee1e3"; 到 bigInt,理想情况下,我想将 hexStr 转换为十进制形式的 bigint,
I can convert a string to a bigInt w/o issues but when the string contains hex values i run into problems
我可以将字符串转换为没有问题的 bigInt,但是当字符串包含十六进制值时,我遇到了问题
采纳答案by Jon Skeet
Have you tried:
你有没有尝试过:
BigInteger bigInt = new BigInteger(hexString, 16);
For example:
例如:
import java.math.*;
public class Test {
public static void main(String[] args) {
String hexStr = "1b0ee1e3";
BigInteger bigInt = new BigInteger(hexStr, 16);
System.out.println(bigInt); // Prints 453960163
}
}