Example usage for java.lang Character forDigit

List of usage examples for java.lang Character forDigit

Introduction

In this page you can find the example usage for java.lang Character forDigit.

Prototype

public static char forDigit(int digit, int radix) 

Source Link

Document

Determines the character representation for a specific digit in the specified radix.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    System.out.printf("Convert digit to character: %s\n", Character.forDigit(12, 2));

}

From source file:Main.java

public static void main(String[] args) {
    int i1 = 5;//from ww  w  . ja  v a  2 s  . c om
    int i2 = 14;

    char ch1 = Character.forDigit(i1, 10);
    char ch2 = Character.forDigit(i2, 16);

    String str1 = "Char representation of " + i1 + " in radix 10 is " + ch1;
    String str2 = "Char representation of " + i2 + " in radix 16 is " + ch2;

    System.out.println(str1);
    System.out.println(str2);
}

From source file:Convert.java

public static void main(String[] args) {
    int i = 0, num = 23658;
    char[] digits = new char[8];

    do {//from www .  java2s.  c  o  m
        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

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));

    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));

}

From source file:Main.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));

    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));
    System.out.println(Float.MIN_VALUE);
    System.out.println(Double.MAX_VALUE);
}

From source file:WrappedClassApp.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));
    System.out.println();/* ww w  .j a va2s  .c o  m*/
    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));
    System.out.println(Float.MIN_VALUE);
    System.out.println(Double.MAX_VALUE);
}

From source file:Main.java

public static String toHexString(byte[] bytes) {
    StringBuffer buffer = new StringBuffer();
    for (byte i : bytes) {
        buffer.append(Character.forDigit((i >> 4) & 0xF, 16));
        buffer.append(Character.forDigit((i & 0xF), 16));
    }/* w  ww .j  a  va 2 s . c  o  m*/

    return buffer.toString();
}

From source file:Main.java

public static String toHex(final byte[] b) {
    final StringBuffer sb = new StringBuffer(b.length * 3);
    for (int i = 0; i < b.length; ++i) {
        sb.append(Character.forDigit((b[i] & 0xF0) >> 4, 16));
        sb.append(Character.forDigit(b[i] & 0xF, 16));
    }/*  ww w  .  j  av  a2  s  .c  o m*/
    return ((sb != null) ? sb.toString().toUpperCase() : null);
}

From source file:Main.java

public static String toHex(byte[] buffer) {
    StringBuffer sb = new StringBuffer(buffer.length * 2);
    for (int i = 0; i < buffer.length; i++) {
        sb.append(Character.forDigit((buffer[i] & 240) >> 4, 16));
        sb.append(Character.forDigit(buffer[i] & 15, 16));
    }//from  ww w.java  2 s .c om
    return sb.toString();
}

From source file:Main.java

private static String toHexString(byte[] bytes) {
    StringBuffer sb = new StringBuffer(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        sb.append(Character.forDigit((bytes[i] & 0XF0) >> 4, 16));
        sb.append(Character.forDigit(bytes[i] & 0X0F, 16));
    }//from  w w w .j  av  a 2 s  .co m
    return sb.toString();
}