0

I have binary array i converted into hex using

    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) 
    {
        sb.append(String.format("%02X ", b));
    }
    System.out.println(sb.toString());

But it gives me hex code for its respective bit.

I want hex containing 8bits. Please help me.

4

1 回答 1

1

你想要这样的东西-

BigInteger bInt = new BigInteger(1, bytes);
String hexString = String.format("%0" + (bytes.length << 1) + "X", bInt);

对于小写十六进制数字,您可以使用 -

String hexString = String.format("%0" + (bytes.length << 1) + "x", bInt);
于 2013-08-26T10:31:53.453 回答