相关疑难解决方法(0)

Java中的十六进制到整数

我试图将String十六进制转换为整数.字符串十六进制是从散列函数(sha-1)计算的.我收到此错误:java.lang.NumberFormatException.我猜它不喜欢十六进制的String表示.我怎样才能做到这一点.这是我的代码:

public Integer calculateHash(String uuid) {

    try {
        MessageDigest digest = MessageDigest.getInstance("SHA1");
        digest.update(uuid.getBytes());
        byte[] output = digest.digest();

        String hex = hexToString(output);
        Integer i = Integer.parseInt(hex,16);
        return i;           

    } catch (NoSuchAlgorithmException e) {
        System.out.println("SHA1 not implemented in this system");
    }

    return null;
}   

private String hexToString(byte[] output) {
    char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            'A', 'B', 'C', 'D', 'E', 'F' };
    StringBuffer buf = new StringBuffer();
    for (int j = 0; j < …
Run Code Online (Sandbox Code Playgroud)

java hex integer

29
推荐指数
1
解决办法
10万
查看次数

标签 统计

hex ×1

integer ×1

java ×1