Here you can find the source of toHex(String val)
public static String toHex(String val)
//package com.java2s; public class Main { public static String toHex(String val) { String ret = "0x"; for (int i = 0; i < val.length(); i++) { ret += toHex(val.charAt(i), 2); }/*from w w w . j av a 2 s. com*/ return ret; } public static String toHex(char c, int width) { int i = (int) c; return toHex(i, width); } public static String toHex(int val, int width) { String s = Integer.toHexString(val).toUpperCase(); while (s.length() < width) { s = "0" + s; } return s; } }