Here you can find the source of toHex16(int w)
public static String toHex16(int w)
//package com.java2s; //License from project: Open Source License public class Main { public static String toHex16(int w) { return toHex((byte) (0xff & (w >> 8))) + toHex((byte) (0xff & w)); }// w w w. j a v a2 s . co m public static String toHex(byte b) { String s; int iByte = b & 0xff; if (iByte < 16) { s = "0" + Integer.toHexString(iByte); } else { s = Integer.toHexString(iByte); } return s.toUpperCase(); } public static String toHex(byte[] data) { return toHex(data, data.length); } public static String toHex(byte[] data, int size) { return toHex(data, 0, size); } public static String toHex(byte[] data, int start, int size) { StringBuffer sb = new StringBuffer(); int count = 0; for (int i = 0; i < size; i++) { byte b = data[start + i]; if (++count > size) { break; } if (sb.length() > 0) { sb.append(' '); } sb.append(toHex(b)); } return sb.toString(); } }