Java Byte Array to Hex bytesToHex(byte[] data)

Here you can find the source of bytesToHex(byte[] data)

Description

bytes To Hex

License

Open Source License

Declaration

public static String bytesToHex(byte[] data) 

Method Source Code

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

public class Main {
    public static String bytesToHex(byte[] data) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            buf.append(byteToHex(data[i]).toUpperCase());
        }//from  w  ww.j a  v  a2 s .c o  m
        return (buf.toString());
    }

    public static String byteToHex(byte data) {
        StringBuffer buf = new StringBuffer();
        buf.append(toHexChar((data >>> 4) & 0x0F));
        buf.append(toHexChar(data & 0x0F));
        return buf.toString();
    }

    public static char toHexChar(int i) {
        if ((0 <= i) && (i <= 9)) {
            return (char) ('0' + i);
        } else {
            return (char) ('a' + (i - 10));
        }
    }
}

Related

  1. bytesToHex(byte[] bytes)
  2. bytesToHex(byte[] bytes)
  3. bytesToHex(byte[] bytes, byte[] hex, int offset)
  4. bytesToHex(byte[] bytes, int groupSize)
  5. bytesToHex(byte[] bytes, int size, char delim)
  6. bytesToHex(byte[] data)
  7. bytesToHex(byte[] data)
  8. bytesToHex(byte[] data)
  9. bytesToHex(byte[] data)