Java Hex Calculate toHexString(final byte[] arr)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(final byte[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toHexString(final byte[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toHexString(arr[i]));
        }/* ww  w .  jav  a 2  s  .  c  o m*/
        buffer.append(']');
        return buffer.toString();
    }

    public static String toHexString(final char[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toHexString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toHexString(final short[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toHexString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toHexString(final int[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toHexString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toHexString(final long[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Long.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Long.toHexString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toHexString(final float[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Float.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Float.toHexString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toHexString(final double[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Double.toHexString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Double.toHexString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }
}

Related

  1. toHexString(char c)
  2. toHexString(final byte b)
  3. toHexString(final byte b)
  4. toHexString(final byte hex)
  5. toHexString(final byte value)
  6. toHexString(final byte[] array)
  7. toHexString(final byte[] b)
  8. toHexString(final byte[] bs)
  9. toHexString(final byte[] bs, final char[] myDigits)