【发布时间】:2023-02-20 21:50:40
【问题描述】:
我正在尝试将字符串 ABCDEF1234567890 转换为十进制值:
long result = 0;
String hex = "0123456789ABCDEF";
decimal = decimal.toUpperCase();
for(int i = 0; i < decimal.length(); i++) {
char c = decimal.charAt(i);
result += hex.indexOf(c) * Math.pow(16, decimal.length() - 1 - i);
}
return Long.toString(result);
我知道 BigInteger 类,但我不知道如何在我的代码中使用它。请帮我
【问题讨论】:
-
BigInteger是去这里的路。你读过课程的文档了吗? -
我不知道如何在我的代码中使用它。你能帮助我吗
-
你可以从
BigInteger result = BigInteger.ZERO;开始。那就看看result有哪些方法吧。 -
new BigInteger(decimal, 16)?
标签: java hex decimal biginteger