바이트 배열을 정수 형식의 16 진수로 변환하는 다음 함수가 있습니다.16 진수 배열을 16 진수로 (int 형식으로)
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;
}
-
그리고 오류가 아래 얻고있다. 포맷터 값이 이미 16 진수임을 알고 있지만 정수 형식으로 저장하고 싶습니다.
어떻게 진행하나요?
Exception in thread "main" java.lang.NumberFormatException: For input string: "202e4724bb138c1c60470adb623ac932"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
'202e4724bb138c1c60470adb623ac932'는'int '가 아니기 때문에이 예외가 발생합니다. – Maroun