List of utility methods to do Hex String Create
int | hexCharToInt(char c) hex Char To Int if (c >= '0' && c <= '9') return (c - '0'); if (c >= 'A' && c <= 'F') return (c - 'A' + 10); if (c >= 'a' && c <= 'f') return (c - 'a' + 10); throw new RuntimeException("invalid hex char '" + c + "'"); |
void | hexDecode(String str, byte[] ba, int len) hex Decode char[] cp = str.toCharArray(); byte nbl = 0; int i = 0; int icp = 0; int iba = 0; for (; i < len; i++, icp++) { if (cp[icp] >= '0' && cp[icp] <= '9') nbl = (byte) (cp[icp] - '0'); ... |
String | hexEncode(byte[] aInput) hex Encode StringBuilder result = new StringBuilder(); char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; for (int idx = 0; idx < aInput.length; ++idx) { byte b = aInput[idx]; result.append(digits[(b & 0xf0) >> 4]); result.append(digits[b & 0x0f]); return result.toString(); |
String | hexify(byte bytes[]) hexify char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; StringBuffer buf = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; ++i) { buf.append(hexDigits[(bytes[i] & 0xf0) >> 4]); buf.append(hexDigits[bytes[i] & 0x0f]); return buf.toString(); ... |
String | toHex(String str) to Hex String hexString = "0123456789ABCDEF"; byte[] bytes = str.getBytes(); StringBuilder sb = new StringBuilder(bytes.length * 2); for (byte aByte : bytes) { char temp1 = hexString.charAt((aByte & 0xf0) >> 4); char temp2 = hexString.charAt(aByte & 0x0f); if (!(temp1 == '0' && temp2 == '0')) { sb.append(temp1); ... |
String | toHex(String txt) to Hex return toHex(txt.getBytes());
|
String | toHex(byte b) Encodes a single byte to hex symbols. StringBuilder sb = new StringBuilder(); appendByteAsHex(sb, b); return sb.toString(); |
String | toHex(byte input[]) to Hex if (input == null) return null; StringBuffer output = new StringBuffer(input.length * 2); for (int i = 0; i < input.length; i++) { int current = input[i] & 0xff; if (current < 16) output.append("0"); output.append(Integer.toString(current, 16)); ... |
String | toHex(byte[] bytes) to Hex BigInteger bi = new BigInteger(1, bytes); return String.format("%0" + (bytes.length << 1) + "X", bi); |
String | toHex(byte[] data) to Hex if (data == null || data.length == 0) return null; StringBuilder stringBuilder = new StringBuilder(data.length * 2); Formatter formatter = null; try { formatter = new Formatter(stringBuilder); for (byte b : data) { formatter.format("%02x", b); ... |