Here you can find the source of toHexString(byte[] bytes)
Parameter | Description |
---|---|
bytes | the bytes array |
public static final String toHexString(byte[] bytes)
//package com.java2s; public class Main { /**/*from www . j a v a 2 s. co m*/ * Returns a string representings the hexadecimal values of the bytes. If the * bytes supplied is null or an empty array, then an empty string in returned. * * @param bytes the bytes array * @return String of hexadecimal representing the bytes */ public static final String toHexString(byte[] bytes) { if (bytes == null || bytes.length == 0) { return ""; } StringBuffer buffer = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { if (((int) bytes[i] & 0xff) < 0x10) { buffer.append("0"); } buffer.append(Long.toString((int) bytes[i] & 0xff, 16)); } return buffer.toString(); } }