u32
stands for unsigned integers that are 32-bit. We can use the from_str_radix()
method of this integer type to convert a string or a character of any base or radix to base 10.
u32::from_str_radix(string, radix)
string
: This is the string whose equivalent we want to get in base 10.
radix
: This is the radix or base for the given string.
The value returned is a base 10 equivalent of the given string.
fn main() {// get the base ten equivalent of a value in any radixprintln!("{:?}", u32::from_str_radix("B", 16)); // string in base 16println!("{:?}", u32::from_str_radix("111", 2)); // string in base 2println!("{:?}", u32::from_str_radix("34", 8)); // string in base 8println!("{:?}", u32::from_str_radix("A3", 16)); // string in base 16println!("{:?}", u32::from_str_radix("1001", 2)); // string in base 2println!("{:?}", u32::from_str_radix("D5", 16)); // string in base 16}
u32::from_str_radix()
method in Rust.