List of usage examples for java.lang Character digit
public static int digit(int codePoint, int radix)
From source file:Main.java
/** * Converts a hex string to a byte array. *///from www .j a v a2 s .c om public static byte[] convertToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); } return data; }
From source file:Main.java
public static byte[] hexStringToByteArray(String s) { if (s != null && !s.equals("")) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); }// w ww .j a v a2s. c o m return data; } return null; }
From source file:Main.java
public static byte[] hexStringToByte(String hex) { int len = (hex.length() / 2); byte[] result = new byte[len]; hex = hex.toLowerCase();/* w w w. j av a 2 s.co m*/ int k = 0; for (int i = 0; i < result.length; i++) { byte high = (byte) (Character.digit(hex.charAt(k), 16) & 0xff); byte low = (byte) (Character.digit(hex.charAt(k + 1), 16) & 0xff); result[i] = (byte) (high << 4 | low); k += 2; } return result; }
From source file:Main.java
public static byte[] toByteArray(String s) { // s guaranteed valid by caller. int len = s.length(); byte[] bytes = new byte[len / 2]; for (int i = 0; i < len; i += 2) { bytes[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); }//w w w .ja v a 2s . c om return bytes; }
From source file:Main.java
public static byte[] convertHexToBytes(String hexString) { if (hexString == null) { return null; }/*from w w w. ja v a2 s.c o m*/ int len = hexString.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); } return data; }
From source file:Main.java
public static byte[] hexToBytes(String hex) { if (hex == null) { return null; }/*from w w w. j a v a 2 s . c o m*/ int len = hex.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return data; }
From source file:Main.java
public static byte[] hexStringToByteArray(String paramString) { int j = paramString.length(); byte[] arrayOfByte = new byte[j / 2]; int i = 0;/*from w ww. j a v a 2 s . c o m*/ for (;;) { if (i >= j) { return arrayOfByte; } arrayOfByte[(i / 2)] = ((byte) ((Character.digit(paramString.charAt(i), 16) << 4) + Character.digit(paramString.charAt(i + 1), 16))); i += 2; } }
From source file:Main.java
public static byte[] hexStringToByteArray(final String byteString) { String value = byteString.replaceAll("[^A-Za-z0-9]", ""); int len = value.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(value.charAt(i), 16) << 4) + Character.digit(value.charAt(i + 1), 16)); }//from w ww . ja v a2 s . co m return data; }
From source file:Main.java
public static byte[] hexToBytes(String hexString) { int len = hexString.length(); byte[] array = new byte[len / 2]; for (int i = 0; i < len; i += 2) { array[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); }// w w w . ja va2 s. c o m return array; }
From source file:Main.java
public static byte[] hexStringToBytes(String s) { if (s == null || s.length() == 0) return null; int len = s.length(); if (len % 2 != 0) { s = '0' + s; len++;/* w ww. jav a 2s .c o m*/ } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); } return data; }