Here you can find the source of bytes2hex(byte[] bytes)
Parameter | Description |
---|---|
bytes | byte stream array |
public static String bytes2hex(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w . j a v a 2 s . c om*/ * This method converts byte stream to a hex string * @param bytes byte stream array * @return the hex string */ public static String bytes2hex(byte[] bytes) { if (bytes != null) { StringBuilder hexString = new StringBuilder(); // bytes to hex for (byte b : bytes) { String strHex = Integer.toHexString(b & 0xFF); if (strHex.length() < 2) { hexString.append(0); } hexString.append(strHex); } return hexString.toString().toUpperCase(); } else throw new NullPointerException("Null bytes"); //TODO: Null Pointer! } }