Java Hex Calculate toHexString0x(byte[] byteArray)

Here you can find the source of toHexString0x(byte[] byteArray)

Description

to Hex Stringx

License

Apache License

Declaration

public static String toHexString0x(byte[] byteArray) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static final String hexChars = "0123456789ABCDEF";

    public static String toHexString0x(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }//from  w w w  . java2 s  . c  o m
        return "0x" + toHexString(byteArray);
    }

    public static String toHexString(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }
        final StringBuilder sb = new StringBuilder(2 + 2 * byteArray.length);
        for (final byte b : byteArray) {
            sb.append(hexChars.charAt((b & 0xF0) >> 4)).append(hexChars.charAt((b & 0x0F)));
        }
        return sb.toString();
    }
}

Related

  1. toHexString(String s)
  2. toHexString(String s)
  3. toHexString(String str)
  4. toHexString(String str)
  5. toHexString(StringBuffer buffer, byte[] bytes, int numBytes)
  6. toHexString2(int i)
  7. toHexString3(byte aByte)
  8. toHexStringBE(char[] array)
  9. toHexStringLE(byte n)