## java.lang.Character digit(int codePoint, int radix)

## Description

If the radix is not in the range MIN_RADIX ≤ radix ≤ MAX_RADIX or if the character is not a valid digit in the specified radix, -1 is returned. A character is a valid digit if at least one of the following is true:

- The method isDigit(codePoint) is true of the character and the Unicode decimal digit value of the character (or its single-character decomposition) is less than the specified radix. In this case the decimal digit value is returned.
- The character is one of the uppercase Latin letters ‘A’ through ‘Z’ and its code is less than radix + ‘A’ – 10. In this case, codePoint – ‘A’ + 10 is returned.
- The character is one of the lowercase Latin letters ‘a’ through ‘z’ and its code is less than radix + ‘a’ – 10. In this case, codePoint – ‘a’ + 10 is returned.
- The character is one of the fullwidth uppercase Latin letters A (‘uFF21’) through Z (‘uFF3A’) and its code is less than radix + ‘uFF21’ – 10. In this case, codePoint – ‘uFF21’ + 10 is returned.
- The character is one of the fullwidth lowercase Latin letters a (‘uFF41’) through z (‘uFF5A’) and its code is less than radix + ‘uFF41’- 10. In this case, codePoint – ‘uFF41’ + 10 is returned.

The digit(int codePoint, int radix) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

1 |
Character.digit(int codePoint, int radix) |

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java digit() method non statically.

## Method Syntax

public static int digit(int codePoint, int radix)

## Method Argument

Data Type | Parameter | Description |
---|---|---|

int | codePoint | the character (Unicode code point) to be converted. |

int | radix | the radix. |

## Method Returns

The digit(int codePoint, int radix) method of Character class returns the numeric value represented by the character in the specified radix.

## Compatibility

Requires Java 1.5 and up

## Java Character digit(int codePoint, int radix) Example

Below is a simple java example on the usage of digit(int codePoint, int radix) method of Character class.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * digit(int codePoint, int radix) method of Character class. */ public class CharacterDigitCodePointExample { public static void main(String[] args) { // initialize a codepoint int codepoint = 65; // initialize the radix int radix = 16; // convert codepoint to char char ch = (char) codepoint; // convert user input to digit int digit = Character.digit(codepoint,radix); // print the result System.out.println("character '" + ch + "' numeric value is " + digit+" using radix "+radix); } } |

## Sample Output

Below is the sample output when you run the above example.