List of usage examples for java.lang Character digit
public static int digit(int codePoint, int radix)
From source file:MainClass.java
public static void main(String args[]) { System.out.printf("Convert character to digit: %s\n", Character.digit('2', 1)); }
From source file:Main.java
public static void main(String[] args) { int ch1 = 9;// w w w. j a v a2 s.c o m int ch2 = 3; int i1 = Character.digit(ch1, 2); int i2 = Character.digit(ch2, 10); System.out.println("Numeric value of " + ch1 + " in radix 2 is " + i1); System.out.println("Numeric value of " + ch2 + " in radix 10 is " + i2); }
From source file:Main.java
public static void main(String[] args) { char ch1 = '9'; char ch2 = '3'; int i1 = Character.digit(ch1, 2); int i2 = Character.digit(ch2, 10); System.out.println("Numeric value of " + ch1 + " in radix 2 is " + i1); System.out.println("Numeric value of " + ch2 + " in radix 10 is " + i2); }
From source file:Convert.java
public static void main(String[] args) { int i = 0, num = 23658; char[] digits = new char[8]; do {//from w w w. j av a2 s . com digits[i++] = Character.forDigit(num % 16, 16); num /= 16; } while (num != 0); for (int j = 7; j >= 0; j--) System.out.println(digits[j]); char[] hex = { 'f', '3', '6', '0' }; num = 0; for (int j = 0; j < hex.length; j++) { num <<= 4; num += Character.digit(hex[j], 16); } System.out.println(num); }
From source file:Main.java
protected static int toDigit(char ch, int index) { int digit = Character.digit(ch, 16); if (digit == -1) { throw new RuntimeException("Illegal hexadecimal character " + ch + " at index " + index); }/* ww w. ja va 2s.c o m*/ return digit; }
From source file:Main.java
public static byte[] HexToBytes(String in) { int len = in.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(in.charAt(i), 16) << 4) + Character.digit(in.charAt(i + 1), 16)); }/*ww w. ja v a 2 s . c o m*/ return data; }
From source file:Main.java
private static byte[] hexStringToByteArray(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)); }/* w w w . j av a 2s . c o m*/ return data; }
From source file:Main.java
public static byte[] hexStringToByteArray(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)); }// ww w . ja v a 2 s . c om return data; }
From source file:Main.java
public static byte[] hexStringToByteArray(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)); }//w w w. j a v a 2s .c o m return data; }
From source file:Main.java
public static byte[] hexStringToByteArray(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)); }/* ww w . j a v a 2 s .c o m*/ return data; }