Pregunta

Is there any way of converting from byte[] to hex representation? I've search everywhere but i can't find anything! Can someone please help me?

¿Fue útil?

Solución

try this:

private static String   digits = "0123456789abcdef";


   public static String toHex(byte[] data){
    StringBuffer    buf = new StringBuffer();

    for (int i = 0; i != data.length; i++)
    {
        int v = data[i] & 0xff;

        buf.append(digits.charAt(v >> 4));
        buf.append(digits.charAt(v & 0xf));
    }

    return buf.toString();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top