Function core::char::from_digit1.0.0[][src]

pub fn from_digit(num: u32, radix: u32) -> Option<char>
Expand description

Converts a digit in the given radix to a char.

A ‘radix’ here is sometimes also called a ‘base’. A radix of two indicates a binary number, a radix of ten, decimal, and a radix of sixteen, hexadecimal, to give some common values. Arbitrary radices are supported.

from_digit() will return None if the input is not a digit in the given radix.


Panics if given a radix larger than 36.


Basic usage:

use std::char;

let c = char::from_digit(4, 10);

assert_eq!(Some('4'), c);

// Decimal 11 is a single digit in base 16
let c = char::from_digit(11, 16);

assert_eq!(Some('b'), c);

Returning None when the input is not a digit:

use std::char;

let c = char::from_digit(20, 10);

assert_eq!(None, c);

Passing a large radix, causing a panic:

use std::char;

// this panics
let c = char::from_digit(1, 37);