List of utility methods to do Hex Convert To
byte[] | fromHexBinary(String s) from Hex Binary int len = s.length(); if (len % 2 != 0) return null; byte out[] = new byte[len / 2]; for (int i = 0; i < len; i += 2) { int h = hexToBin(s.charAt(i)); int l = hexToBin(s.charAt(i + 1)); if (h == -1 || l == -1) ... |
int | fromHexChar(char ch) Convert the given hex character (0-9, A-Z, or a-z) into its decimal equivalent value. switch (ch) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': ... |
int | fromHexChars(char[] chars, int i) from Hex Chars int n1 = chars[i] >= 'A' ? (10 + (chars[i] - 'A')) : (chars[i] - '0'); i++; int n2 = chars[i] >= 'A' ? (10 + (chars[i] - 'A')) : (chars[i] - '0'); byte b = (byte) ((n1 << 4) | n2); return b & 0xFF; |
byte[] | fromHexDigest(String hexDigest) from Hex Digest if (hexDigest == null || hexDigest.length() == 0) { return null; hexDigest = hexDigest.toLowerCase(); int digestLength = hexDigest.length() / 2; if (digestLength == 0 || 2 * digestLength != hexDigest.length()) { return null; byte[] digest = new byte[digestLength]; for (int i = 0; i < hexDigest.length() / 2; i++) { if (!isHex(hexDigest.charAt(2 * i)) || !isHex(hexDigest.charAt(2 * i + 1))) { return null; int hi = Character.digit(hexDigest.charAt(2 * i), 16) << 4; int lo = Character.digit(hexDigest.charAt(2 * i + 1), 16); Integer ib = new Integer(hi | lo); byte b = ib.byteValue(); digest[i] = b; return digest; |
int | fromHexDigit(final char c) from Hex Digit final int ret = Character.digit(c, 16); if (ret == -1) { throw new NumberFormatException("Not a valid hex digit: " + c); return ret; |
int | fromHexDigit(int c) from Hex Digit if (c >= 0x30 && c < 0x3A) return c - 0x30; else if (c >= 0x41 && c < 0x47) return c - 0x37; else if (c >= 0x61 && c < 0x67) return c - 0x57; else throw new NumberFormatException('\'' + c + "' is not a valid hexadecimal digit."); ... |
byte | fromHexNibble(char n) Convert a hexadecimal digit to a byte. if (n <= '9') return (byte) (n - '0'); if (n <= 'G') return (byte) (n - ('A' - 10)); return (byte) (n - ('a' - 10)); |
byte | fromHexNibble(final char n) Convierte un caracter de texto hexadecimal a su equivalente binario. if (n <= '9') { return (byte) (n - '0'); if (n <= 'G') { return (byte) (n - ('A' - 10)); return (byte) (n - ('a' - 10)); |
int | fromHexShort(char a) from Hex Short if (a >= '0' && a <= '9') { return a - '0'; if (a >= 'a' && a <= 'f') { return 10 + (a - 'a'); throw new RuntimeException(); |
int[] | fromHexStr(final String data) Convert a string with hex encoded bytes. final int length = data.length(); if (length % 2 != 0) throw new IllegalArgumentException("Length of hex data must be a multiple of 2!"); final int size = length / 2; final int[] result = new int[size]; for (int i = 0; i < size; i++) { final int pos = i * 2; result[i] = Integer.parseInt(data.substring(pos, pos + 2), 16); ... |