Java Hex Calculate toHex(byte[] data)

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

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte[] data) 

Method Source Code

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

public class Main {
    protected static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
            'D', 'E', 'F' };

    public static String toHex(byte[] data) {
        char[] str = new char[data.length + data.length];
        for (int i = data.length - 1, strIndex = str.length - 1; i >= 0; i--) {
            byte byte4i = data[i];
            str[strIndex--] = hexDigits[byte4i & 0xF];
            str[strIndex--] = hexDigits[byte4i >>> 4 & 0xF];
        }/*ww  w  .j  av  a  2s.  c  o m*/
        return new String(str);
    }
}

Related

  1. toHex(byte[] bytes)
  2. toHex(byte[] bytes)
  3. toHex(byte[] bytes)
  4. toHex(byte[] bytes, int maxlen)
  5. toHex(byte[] data)
  6. toHex(byte[] data)
  7. toHex(byte[] data)
  8. toHex(byte[] data)
  9. toHex(byte[] data)