Q:

Rust program to create a variable with binary value and print it in decimal number

belongs to collection: Rust Basic Programs

0

Here, we will create a 32-bit signed integer variable with a binary value and print the corresponding decimal number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to create a variable with binary value and print it in a decimal number is given below. The given program is compiled and executed successfully.

// Rust program to create a variable with binary value 
// and print it in decimal number

fn main() {
    let mut num:i32=0b10101101;  
    println!("Decimal number: {}",num);
}

Output:

Decimal number: 173

Explanation:

Here, we created a variable num initialized with a binary number. Then we printed the corresponding decimal number.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to create a variable with hexadecimal... >>
<< Rust program to demonstrate the isize and usize da...