Java Hex Calculate toHexString(byte b[])

Here you can find the source of toHexString(byte b[])

Description

Byte array to Hex string

License

Open Source License

Parameter

Parameter Description
b a parameter

Declaration

public static String toHexString(byte b[]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static char hexChar[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    /**//from w  w  w .ja  v a2 s .c  om
     * Byte array to Hex string
     * 
     * @param b
     * @return
     */
    public static String toHexString(byte b[]) {
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            sb.append(hexChar[(b[i] & 0xf0) >>> 4]);
            sb.append(hexChar[b[i] & 0xf]);
        }

        return sb.toString();
    }
}

Related

  1. toHexString(byte b)
  2. toHexString(byte b)
  3. toHexString(byte b[])
  4. toHexString(byte b[])
  5. toHexString(byte b[])
  6. toHexString(byte buffer[])
  7. toHexString(byte buffer[])
  8. toHexString(byte bytes[])
  9. toHexString(byte bytes[])