Java Byte Array Create ToByteArrayString(byte[] bytes)

Here you can find the source of ToByteArrayString(byte[] bytes)

Description

To Byte Array String

License

Creative Commons License

Declaration

public static String ToByteArrayString(byte[] bytes) 

Method Source Code

//package com.java2s;

public class Main {
    public static String ToByteArrayString(byte[] bytes) {
        if (bytes == null) {
            return "null";
        }/*from  w  ww. ja  v  a 2s.  c  om*/
        StringBuilder sb = new StringBuilder();
        String hex = "0123456789ABCDEF";
        sb.append("new byte[] { ");
        for (int i = 0; i < bytes.length; ++i) {
            if (i > 0) {
                sb.append(", ");
            }
            if ((bytes[i] & 0x80) != 0) {
                sb.append("(byte)0x");
            } else {
                sb.append("0x");
            }
            sb.append(hex.charAt((bytes[i] >> 4) & 0xf));
            sb.append(hex.charAt(bytes[i] & 0xf));
        }
        sb.append("}");
        return sb.toString();
    }
}

Related

  1. toByteArrayMM(int value)
  2. toByteArrayNoConversion(String textz)
  3. toByteArrays(String s)
  4. toByteArrayShifted(int... arguments)
  5. toByteArrayShifted2(int[][] intArray)
  6. toByteArrayV4(String address)
  7. toByteArrayV6(String address)
  8. toByteInfo(long bytes)
  9. toBytes(boolean[] input)