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

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

Description

Converts a byte array to a representative string of hex digits.

License

Open Source License

Parameter

Parameter Description
b byte array to convert

Return

representative string of hex digits

Declaration

public static String bytesToHex(byte[] b) 

Method Source Code

//package com.java2s;
//    it under the terms of the GNU Lesser General Public License as published

public class Main {
    /**/* w  w w  . j  ava2s.c om*/
     * Converts a byte array to a representative string of hex digits.
     * @param b byte array to convert
     * @return representative string of hex digits
     */
    public static String bytesToHex(byte[] b) {
        String s = "";
        for (int i = 0; i < b.length; i++) {
            if (i > 0 && i % 4 == 0) {
                s += " ";
            }
            s += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
        }
        return s;
    }
}

Related

  1. bytesToHex(byte in[])
  2. bytesToHex(byte... bytes)
  3. bytesToHex(byte[] a)
  4. bytesToHex(byte[] a)
  5. bytesToHex(byte[] array)
  6. bytesToHex(byte[] b)
  7. bytesToHex(byte[] b)
  8. bytesToHex(byte[] b)
  9. bytesToHex(byte[] b, int offset, int length)