Java Byte to Hex String byteToHexString(byte[] bytes, int start, int end)

Here you can find the source of byteToHexString(byte[] bytes, int start, int end)

Description

Given an array of bytes it will convert the bytes to a hex string representation of the bytes

License

Open Source License

Parameter

Parameter Description
bytes a parameter
start start index, inclusively
end end index, exclusively

Return

hex string representation of the byte array

Declaration

public static String byteToHexString(byte[] bytes, int start, int end) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w . ja va  2s  .  c om
     * Given an array of bytes it will convert the bytes to a hex string representation of the bytes
     * 
     * @param bytes
     * @param start
     *            start index, inclusively
     * @param end
     *            end index, exclusively
     * @return hex string representation of the byte array
     */
    public static String byteToHexString(byte[] bytes, int start, int end) {
        if (bytes == null) {
            throw new IllegalArgumentException("bytes == null");
        }
        StringBuilder s = new StringBuilder();
        for (int i = start; i < end; i++) {
            s.append(String.format("%02x", bytes[i]));
        }
        return s.toString();
    }

    /** Same as byteToHexString(bytes, 0, bytes.length). */
    public static String byteToHexString(byte bytes[]) {
        return byteToHexString(bytes, 0, bytes.length);
    }

    public static String toString(String[] content, String sign) {
        if (null == content) {
            return null;
        }

        sign = null == sign ? "," : sign;
        StringBuilder strBuilder = new StringBuilder();
        for (int i = 0; i < content.length; i++) {
            strBuilder.append(content[i]);
            if (i < content.length - 1) {
                strBuilder.append(sign);
            }
        }

        return strBuilder.toString();
    }
}

Related

  1. byteToHexString(byte value)
  2. byteToHexString(byte[] b)
  3. byteToHexString(byte[] b)
  4. byteToHexString(byte[] bytes)
  5. byteToHexString(byte[] bytes, int start, int end)
  6. byteToHexString(byte[] data)
  7. byteToHexString(final byte b)
  8. byteToHexString(final byte b)
  9. byteToHexString(final byte inbyte)