Function malachite_base::num::conversion::string::from_string::digit_from_display_byte
source · pub const fn digit_from_display_byte(b: u8) -> Option<u8>
Expand description
Produces a digit from a byte corresponding to a numeric or alphabetic (lower- or uppercase)
char
that represents the digit.
Bytes corresponding to char
s from ‘0’ to ‘9’ become digits 0 to 9. Bytes corresponding to
char
s from ‘a’ to ‘z’ become digits 10 to 35. Bytes corresponding to char
s from ‘A’ to ‘Z’
also become digits 10 to 35. Passing a byte that does not correspond to any of these char
s
yields None
.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::conversion::string::from_string::digit_from_display_byte;
assert_eq!(digit_from_display_byte(b'0'), Some(0));
assert_eq!(digit_from_display_byte(b'9'), Some(9));
assert_eq!(digit_from_display_byte(b'a'), Some(10));
assert_eq!(digit_from_display_byte(b'z'), Some(35));
assert_eq!(digit_from_display_byte(b'A'), Some(10));
assert_eq!(digit_from_display_byte(b'Z'), Some(35));
assert_eq!(digit_from_display_byte(b' '), None);
assert_eq!(digit_from_display_byte(b'!'), None);