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

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

Description

to Hex

Declaration

private static String toHex(byte[] buf) 

Method Source Code

//package com.java2s;

public class Main {
    private final static String HEX = "0123456789ABCDEFG";

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

    private 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) {
        sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
    }
}

Related

  1. byteArray2HexString(byte[] data)
  2. Convert2bytesHexaFormatToInt(byte[] ArrayToConvert)
  3. ConvertHexByteArrayToString( byte[] byteArrayToConvert)
  4. toHex(byte[] array)
  5. toHex(byte[] array, int offset, int len)
  6. toHex(byte[] bytes)
  7. toHex(byte[] bytes)
  8. toHex(byte[] bytes, String separator)
  9. toHex(byte[] bytes, int offset, int length)