Here you can find the source of bytesToHexString(byte[] bytes)
Parameter | Description |
---|---|
bytes | a parameter |
public static String bytesToHexString(byte[] bytes)
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static String bytesToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(""); if (bytes == null || bytes.length <= 0) { return null; }//from w ww. ja va 2 s . co m for (int i = 0; i < bytes.length; i++) { int v = bytes[i] & 0xFF; String hv = Integer.toHexString(v); if (hv.length() < 2) { sb.append(0); } sb.append(hv); } return sb.toString(); } public static String toHexString(String str) { byte[] byteArray; try { byteArray = str.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); byteArray = str.getBytes(); } return bytesToHexString(byteArray); } }