【发布时间】:2015-01-13 11:52:07
【问题描述】:
我有以下函数将字节数组转换为整数格式的十六进制。
private static int byteArray2Int(final byte[] hash) {
Formatter formatter = new Formatter();
for (byte b : hash) {
formatter.format("%02x", b);
}
String str = formatter.toString();
int hex = Integer.parseInt(str, 16); //number format exception
return hex;
}
--
而且我遇到了错误。我知道格式化程序的值已经是十六进制,但我想以整数格式存储。
请问我该怎么做?
Exception in thread "main" java.lang.NumberFormatException: For input string: "202e4724bb138c1c60470adb623ac932"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
【问题讨论】:
-
202e4724bb138c1c60470adb623ac932不是int,这就是您收到此异常的原因。
标签: java hex bytearray type-conversion numberformatexception