List of utility methods to do Hex Convert To
byte[] | fromHexString(String s) from Hex String if (s.length() % 2 != 0) throw new IllegalArgumentException(s); byte[] array = new byte[s.length() / 2]; for (int i = 0; i < array.length; i++) { int b = Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16); array[i] = (byte) (0xff & b); return array; ... |
byte[] | fromHexString(String s) Decode a Hex-String to a byte Array. if (!s.matches(REGEXP_HEX)) throw new IllegalArgumentException("cannot parse '" + s + "'"); int length = (int) Math.ceil(s.length() / 2.0); byte[] bytes = new byte[length]; int c = s.length() - 2; for (int i = length - 1; i >= 0; i--) { bytes[i] = (byte) Integer.parseInt(s.substring(c < 0 ? 0 : c, c + 2), 16); c = c - 2; ... |
byte[] | fromHexString(String s) from Hex String if (s.length() % 2 != 0) throw new IllegalArgumentException(s); byte[] array = new byte[s.length() / 2]; for (int i = 0; i < array.length; i++) { int b = Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16); array[i] = (byte) (0xff & b); return array; ... |
byte[] | fromHexString(String s) from Hex String int len = s.length(); if ((len & 1) != 0) { s = (new StringBuilder()).append("0").append(s).toString(); len = s.length(); byte b[] = new byte[len / 2]; int i = 0; for (int j = 0; i < len; j++) { ... |
byte[] | fromHexString(String s) Convert a string containing hexadecimal characters to a byte-array. char[] rawChars = s.toUpperCase().toCharArray(); int hexChars = 0; for (int i = 0; i < rawChars.length; i++) { if ((rawChars[i] >= '0' && rawChars[i] <= '9') || (rawChars[i] >= 'A' && rawChars[i] <= 'F')) { hexChars++; byte[] byteString = new byte[(hexChars + 1) >> 1]; ... |
byte[] | fromHexString(String s, int offset, int length) Convert a hexidecimal string generated by toHexString() back into a byte array. if ((length % 2) != 0) return null; byte[] byteArray = new byte[length / 2]; int j = 0; int end = offset + length; for (int i = offset; i < end; i += 2) { int high_nibble = Character.digit(s.charAt(i), 16); int low_nibble = Character.digit(s.charAt(i + 1), 16); ... |
byte[] | fromHexString(String str) from Hex String str = cleanHexString(str); int stringLength = str.length(); if ((stringLength & 0x1) != 0) { throw new IllegalArgumentException("fromHexString requires an even number of hex characters"); byte[] b = new byte[stringLength / 2]; for (int i = 0, j = 0; i < stringLength; i += 2, j++) { int high = convertChar(str.charAt(i)); ... |
byte[] | fromHexString(String text) Convert a String containing consecutive (no inside whitespace) hexadecimal digits into a corresponding byte array. text = text.trim(); if (text.length() % 2 != 0) text = "0" + text; int resLen = text.length() / 2; int loNibble, hiNibble; byte[] res = new byte[resLen]; for (int i = 0; i < resLen; i++) { int j = i << 1; ... |
byte[] | fromHexString(String value) from Hex String byte[] rs = new byte[value.length() / 2]; for (int i = 0; i < value.length(); i += 2) { String b = value.substring(i, i + 2); rs[i / 2] = Integer.valueOf(b, 16).byteValue(); return rs; |
byte[] | fromHexToBytes(String hex) from Hex To Bytes int x = hex.length() / 2; byte[] b = new byte[x]; int index = 0; for (int i = 0; i < hex.length(); i += 2) { byte b1 = toByte(hex.charAt(i)); byte b2 = toByte(hex.charAt(i + 1)); b[index++] = (byte) ((b1 << 4) + b2); return b; |