How to convert hexadecimal to decimal in Rust

1 Answer

0 votes
use std::i64;

fn main() {
    let hex = "0x1D7F";
    let dec = i64::from_str_radix(&hex[2..], 16).expect("Invalid hex number");

    println!("{}", dec);
}


     
/*
run:
  
7551
    
*/

 



answered Feb 14, 2025 by avibootz

Related questions

...