List of usage examples for java.lang Character digit
public static int digit(int codePoint, int radix)
From source file:Main.java
public static byte[] hexStringToByteArray(String hexString) { 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)); }/* ww w.jav a 2s . c o m*/ return data; }
From source file:Main.java
public static byte[] hexToBytes(String hex) { try {/* w w w . j a va2 s . co m*/ int length = hex.length(); byte[] bytes = new byte[length / 2]; for (int i = 0; i < length; i += 2) { bytes[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return bytes; } catch (Exception e) { Log.e(TAG, "Got Exception: " + e.toString()); return new byte[0]; } }
From source file:Main.java
public static byte[] hexStringToByteArray(String s) { if ((s.length() % 2) != 0) { throw new IllegalArgumentException("Bad input string: " + s); }//w ww . j av a 2 s . c o m 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 Integer[] getDigits(String number) { List<Integer> digits = new ArrayList<Integer>(); for (int i = 0; i < number.length(); i++) { int j = Character.digit(number.charAt(i), 10); digits.add(j);/*from w w w . ja v a2s .c om*/ } return digits.toArray(new Integer[] {}); }
From source file:Util.java
/** * Creates byte array representation of HEX string.<br> * /* w w w . j a v a 2s .c o m*/ * @param s * string to parse * @return */ public static byte[] fromHexString(String s) { int length = s.length() / 2; byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { bytes[i] = (byte) ((Character.digit(s.charAt(i * 2), 16) << 4) | Character.digit(s.charAt((i * 2) + 1), 16)); } return bytes; }
From source file:Main.java
public static boolean isInteger(String s, int radix) { if (s.isEmpty()) return false; for (int i = 0; i < s.length(); i++) { if (i == 0 && s.charAt(i) == '-') { if (s.length() == 1) return false; else// ww w. jav a2 s .c o m continue; } if (Character.digit(s.charAt(i), radix) < 0) return false; } return true; }
From source file:Main.java
public static byte[] hexStringToByteArray(String hexString) { int len = hexString.length(); byte[] data = new byte[(len / SECOND_BITMASK)]; for (int i = 0; i < len; i += SECOND_BITMASK) { data[i / SECOND_BITMASK] = (byte) ((Character.digit(hexString.charAt(i), FIFTH_BITMASK) << THIRD_BITMASK) + Character.digit(hexString.charAt(i + FIRST_BITMASK), FIFTH_BITMASK)); }//from w w w. ja v a 2 s .c o m return data; }
From source file:Main.java
public static String decompress(String hexString) throws UnsupportedEncodingException { final byte[] byteArray = new byte[hexString.length() / 2]; int k = 0;//from ww w . jav a 2 s. c om for (int i = 0; i < byteArray.length; i++) { byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff); byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff); byteArray[i] = (byte) (high << 4 | low); k += 2; } ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(byteArray); try { GZIPInputStream gunzip = new GZIPInputStream(in); byte[] buffer = new byte[256]; int n; while ((n = gunzip.read(buffer)) >= 0) { out.write(buffer, 0, n); } } catch (IOException e) { e.printStackTrace(); } return out.toString(); }
From source file:Main.java
public static byte[] hexStringToByteArray(String hexString) { int len = hexString.length(); byte[] data = new byte[(len / SECOND_BITMASK)]; for (int i = EventIDNotificationAdded; i < len; i += SECOND_BITMASK) { data[i / SECOND_BITMASK] = (byte) ((Character.digit(hexString.charAt(i), FIFTH_BITMASK) << THIRD_BITMASK) + Character.digit(hexString.charAt(i + FIRST_BITMASK), FIFTH_BITMASK)); }/*www . j a va 2s .c o m*/ return data; }
From source file:Main.java
public static boolean isIsracardValid(String cardNumber) { int sum = 0;//from w w w . j a v a 2 s .c o m int len = cardNumber.length(); // If the number is less than 9 digits if (len == 8) { cardNumber = "0" + cardNumber; len++; } for (int i = 0; i < len; i++) { final char c = cardNumber.charAt(i); if (!Character.isDigit(c)) { throw new IllegalArgumentException(String.format("Not a digit: '%s'", c)); } final int digit = Character.digit(c, 10); sum = sum + (digit * (9 - i)); } return sum % 11 == 0; }