Android Byte Array to Hex Convert toHex(byte[] buf)

Here you can find the source of toHex(byte[] buf)

Description

to Hex

Declaration

public static String toHex(byte[] buf) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toHex(String txt) {
        return toHex(txt.getBytes());
    }// w  w  w.j a v  a  2  s  .c o  m

    public static String toHex(byte[] buf) {
        if (buf == null)
            return "";
        StringBuffer result = new StringBuffer(2 * buf.length);
        for (int i = 0; i < buf.length; i++) {
            appendHex(result, buf[i]);
        }
        return result.toString();
    }

    private static void appendHex(StringBuffer sb, byte b) {
        final String HEX = "0123456789ABCDEF";
        sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
    }
}

Related

  1. toHexString(byte[] data, int offset, int length)
  2. toHexStringArray(byte[] data, int offset, int length)
  3. convertToHexString(byte[] input)
  4. dumpHex(byte[] bytes)
  5. getBinaryStrFromByteArr(byte[] bArr)
  6. toHex(byte[] buf)
  7. byte2hex(byte[] b)
  8. byte2hex(byte[] b)
  9. hexEncode(byte[] data)