Android Byte Array to Hex Convert toHexString(byte[] b)

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

Description

Convert a byte array to a hex string.

Parameter

Parameter Description
b The byte array

Return

The hex String

Declaration

public static String toHexString(byte[] b) 

Method Source Code

//package com.java2s;

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

    /**/*from   ww  w  . j a  v  a  2  s . c  o  m*/
     * Convert a byte array to a hex string.
     *
     * @param b The byte array
     * @return The hex String
     */
    public static String toHexString(byte[] b) {
        StringBuffer sb = new StringBuffer(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            // look up high nibble char
            sb.append(hexChar[(b[i] & 0xf0) >>> 4]);

            // look up low nibble char
            sb.append(hexChar[b[i] & 0x0f]);
        }
        return sb.toString();
    }
}

Related

  1. byteArrayToHexString(byte[] b)
  2. bytesToHexString(byte[] bytes)
  3. hex2byte(byte[] b)
  4. toHex(byte[] buf)
  5. toHex(byte[] data)
  6. toHexString(byte[] buf, int offset, int length)
  7. toHexString(byte[] data)
  8. getHexString(byte[] b)
  9. getHexString(byte[] b, String splitString)