Java Hex Calculate toHexString(byte[] data)

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

Description

Produces a string with each byte in two-digit hex and no spaces between each byte.

License

Open Source License

Parameter

Parameter Description
data a parameter

Declaration

public static String toHexString(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   www  .  j  av a 2  s.com*/
     * Produces a string with each byte in two-digit hex
     * and no spaces between each byte.
     * @param data
     * @return
     */
    public static String toHexString(byte[] data) {
        if (data == null) {
            return null;
        }

        // TODO: write more efficient implementation
        String s = "";
        for (int i = 0; i < data.length; i++) {
            byte b = data[i];
            if ((b >= 0) && (b < 16)) {
                s = s + "0";
            }
            s = s + Integer.toHexString(b & 0xff);
        }
        return s;
    }
}

Related

  1. toHexString(byte[] data)
  2. toHexString(byte[] data)
  3. toHexString(byte[] data)
  4. toHexString(byte[] data)
  5. toHexString(byte[] data)
  6. toHexString(byte[] data)
  7. toHexString(byte[] data)
  8. toHexString(byte[] data, final int offset, final int count)
  9. toHexString(byte[] data, int maxLen)