Android Byte Array to Hex Convert getHexString(byte[] b, String splitString)

Here you can find the source of getHexString(byte[] b, String splitString)

Description

get Hex String

License

Open Source License

Declaration

public static String getHexString(byte[] b, String splitString) 

Method Source Code

//package com.java2s;

public class Main {
    public static final String HEX_STRING_BLANK_SPLIT = " ";

    public static String getHexString(byte[] b) {
        return getHexString(b, HEX_STRING_BLANK_SPLIT);
    }// w  ww .  j  a  v a 2s  .c  o m

    public static String getHexString(byte[] b, String splitString) {
        int[] intArray = new int[b.length];
        for (int i = 0; i < b.length; i++) {
            if (b[i] < 0) {
                intArray[i] = b[i] + 256;
            } else {
                intArray[i] = b[i];
            }
        }
        return getHexString(intArray, splitString);
    }

    public static String getHexString(int[] b) {
        return getHexString(b, HEX_STRING_BLANK_SPLIT);
    }

    public static String getHexString(int[] b, String splitString) {
        StringBuffer sb = new StringBuffer();
        for (int c : b) {
            String strData = Integer.toHexString(c);
            if (strData.length() == 1) {
                sb.append("0").append(strData);
            } else {
                sb.append(strData);
            }
            sb.append(splitString);
        }
        return sb.toString().trim();
    }

    public static String getHexString(int i) {
        return getHexString(new int[] { i });
    }

    public static String getHexString(byte i) {
        return getHexString(new byte[] { i });
    }
}

Related

  1. toHex(byte[] data)
  2. toHexString(byte[] b)
  3. toHexString(byte[] buf, int offset, int length)
  4. toHexString(byte[] data)
  5. getHexString(byte[] b)
  6. toHex(byte[] b)
  7. bytesToHexString(byte[] bytes)
  8. hexToHexString(byte[] b)
  9. toHexString(byte[] b)