Here you can find the source of bytesToHex(final byte[] bytes)
Parameter | Description |
---|---|
bytes | The byte array to convert |
public static final String bytesToHex(final byte[] bytes)
//package com.java2s; public class Main { /**//from w ww .j ava2s . com * Convert a byte array to a String of hex characters. * * @param bytes The byte array to convert * @return A hex string */ public static final String bytesToHex(final byte[] bytes) { if (bytes == null) return null; else { int length = bytes.length; String hexBytes = ""; for (int i = 0; i < length; i++) { if ((bytes[i] & 0xFF) < 16) { hexBytes += "0"; hexBytes += Integer.toHexString(bytes[i] & 0xFF); } else hexBytes += Integer.toHexString(bytes[i] & 0xFF); } return hexBytes; } } }