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
Panics if given a radix larger than 36.
Examples
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);
RunReturning None
when the input is not a digit:
use std::char;
let c = char::from_digit(20, 10);
assert_eq!(None, c);
RunPassing a large radix, causing a panic:
ⓘ
use std::char;
// this panics
let c = char::from_digit(1, 37);
Run