Java Hex Calculate toHex(byte[] b)

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

Description

Like DataHelper.toHexString but ensures no loss of leading zero bytes

License

Open Source License

Declaration

public static String toHex(byte[] b) 

Method Source Code

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

public class Main {
    /**//from   ww  w.  j  a  v  a  2  s .  com
     *  Like DataHelper.toHexString but ensures no loss of leading zero bytes
     *  @since 0.8.4
     */
    public static String toHex(byte[] b) {
        StringBuilder buf = new StringBuilder(40);
        for (int i = 0; i < b.length; i++) {
            int bi = b[i] & 0xff;
            if (bi < 16)
                buf.append('0');
            buf.append(Integer.toHexString(bi));
        }
        return buf.toString();
    }
}

Related

  1. toHex(byte[] arr)
  2. toHex(byte[] array)
  3. toHex(byte[] array, int offset, int length)
  4. toHex(byte[] b)
  5. toHex(byte[] b)
  6. toHex(byte[] b)
  7. toHex(byte[] b)
  8. toHex(byte[] b, int off, int len, String separator)
  9. toHEX(byte[] ba)