List of utility methods to do Hex Calculate
String | toHex(byte[] raw) to Hex final String HEXES = "0123456789ABCDEF"; if (raw == null) { return null; final StringBuilder hex = new StringBuilder(2 * raw.length); for (final byte b : raw) { hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))).append(" "); return hex.toString(); |
String | toHex(byte[] raw) to Hex if (raw == null) { return null; int index = 0; final StringBuilder hex = new StringBuilder(2 * raw.length); for (final byte b : raw) { hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))); if (index < raw.length - 1) { ... |
String | toHex(byte[] raw) to Hex if (raw.length != 16) throw new IllegalArgumentException("length must be 16, not " + raw.length); final char[] hex = new char[32]; short i = 0; for (final byte b : raw) { hex[i] = HEXES[(b & 0xF0) >> 4]; hex[i + 1] = HEXES[(b & 0x0F)]; i += 2; ... |
String | ToHex(byte[] src) To Hex String res = ""; for (int i = 0; i < src.length; i++) { res += String.format("%02X", src[i] & 0xFF); return res.toLowerCase(); |
byte[] | toHex(byte[] src) to Hex int l = src.length; byte dst[] = new byte[l * 2]; for (int i = 0, j = 0; i < l; i++) { int k = src[i]; k &= (int) 0xFF; dst[j++] = CHEX[k >> 4]; dst[j++] = CHEX[k & 0x0F]; return dst; |
String | toHex(byte[] text) Utility method which converts a byte[] to a hexadecimal string of characters, in lower case StringBuffer buffer = new StringBuffer(); for (int i = 0; i < text.length; i++) { buffer.append(HEX_ARRAY[0x0f & (text[i] >> 4)]); buffer.append(HEX_ARRAY[0x0f & text[i]]); return buffer.toString(); |
String | toHex(byte[] v) to Hex String out = ""; for (int i = 0; i < v.length; i++) out = out + hex[(v[i] >> 4) & 0xF] + hex[v[i] & 0xF]; return (out); |
String | toHex(byte[] val) to Hex StringBuffer out = new StringBuffer(); for (int i = 0, j = val.length; i < j; i++) { String ve = Integer.toString((((int) ((char) val[i])) & 0xFF), 16); if (ve.length() == 1) { ve = "0" + ve; out.append(ve); return out.toString(); |
String | toHex(byte[] val, int start, int len) Can be used to encode values that contain invalid XML characters. StringBuffer buf = new StringBuffer(); for (int i = 0; i < len; i++) { byte b = val[start + i]; buf.append(DEC2HEX[(b & 0xf0) >> 4]); buf.append(DEC2HEX[b & 0x0f]); return buf.toString(); |
String | toHex(byte[] value) to Hex final StringBuilder b = new StringBuilder(); for (byte c : value) b.append(hex[(c >>> 4) & 0xf]).append(hex[c & 0xf]); return "0x" + b.toString(); |