Converts char digit into integer value. - Java java.lang

Java examples for java.lang:Math Value

Description

Converts char digit into integer value.

Demo Code


import java.math.BigInteger;

public class Main{
    /**//  w ww.java2 s  .c  om
     * Converts char digit into integer value. Accepts numeric chars (0 - 9) as
     * well as letter (A-z).
     */
    public static int parseDigit(char digit) {
        if ((digit >= '0') && (digit <= '9')) {
            return digit - '0';
        }
        if (CharUtil.isLowercaseLetter(digit)) {
            return 10 + digit - 'a';
        }
        return 10 + digit - 'A';
    }
}

Related Tutorials