Java Byte Array to Hex byteToHex(byte[] base)

Here you can find the source of byteToHex(byte[] base)

Description

byte To Hex

License

Apache License

Declaration

public static String byteToHex(byte[] base) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  ww  w. ja va  2  s  .co  m
     * Encodes a byte array (into what i forgot)
     *
     * @param base
     * @return
     */
    //TODO compare the outcome of the above methods with this and eliminate the worst
    private static final char[] TOHEX = "0123456789abcdef".toCharArray();

    public static String byteToHex(byte[] base) {
        char[] c = new char[base.length * 2];
        int i = 0;

        for (byte b : base) {
            int j = b;
            j = j + 128;
            c[i++] = TOHEX[j / 0x10];
            c[i++] = TOHEX[j % 0x10];
        }
        return new String(c);
    }
}

Related

  1. byteToHex(byte bytes[])
  2. byteToHex(byte data)
  3. byteToHex(byte[] array)
  4. byteToHex(byte[] array, String separator)
  5. byteToHex(byte[] b, int size)
  6. byteToHex(byte[] buf)
  7. byteToHex(byte[] buffer)
  8. ByteToHex(byte[] bytes)
  9. byteToHex(byte[] content, int nLength)