Java Hex Calculate toHexString(int[] data)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(int[] data) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toHexString(int[] data) {
        if (data == null)
            return "null";
        StringBuilder stringBuilder = new StringBuilder(data.length * 5);
        stringBuilder.append('[');
        for (int i = 0; i < data.length; i++) {
            stringBuilder.append(String.format("0x%02X", data[i]));
            if (i + 1 < data.length)
                stringBuilder.append(", ");
        }/*from  w w w. j  a va  2  s .  c  o  m*/
        return stringBuilder.append(']').toString();
    }

    public static String toHexString(byte[] data) {
        if (data == null)
            return "null";
        StringBuilder stringBuilder = new StringBuilder(data.length * 5);
        stringBuilder.append('[');
        for (int i = 0; i < data.length; i++) {
            stringBuilder.append(String.format("0x%02X", data[i]));
            if (i + 1 < data.length)
                stringBuilder.append(", ");
        }
        return stringBuilder.append(']').toString();
    }
}

Related

  1. toHexString(int val, int minLength)
  2. toHexString(int value, int len)
  3. ToHexString(int value, int length)
  4. toHexString(int value, int minLength)
  5. toHexString(int value, int numDigits)
  6. toHexString(int[] ia)
  7. toHexString(int[] x, int bitsPerDigit)
  8. toHexString(Integer num)
  9. toHexString(long i)