Here you can find the source of str2HexStr(String str)
public static String str2HexStr(String str)
//package com.java2s; public class Main { public static String str2HexStr(String str) { char[] chars = "0123456789ABCDEF".toCharArray(); StringBuilder sb = new StringBuilder(""); byte[] bs = str.getBytes(); int bit;//from www .j a v a2 s .com for (int i = 0; i < bs.length; i++) { bit = (bs[i] & 0x0f0) >> 4; sb.append("0x"); sb.append(chars[bit]); bit = bs[i] & 0x0f; sb.append(chars[bit]); sb.append(", "); } return sb.toString(); } }