Q:

Rust program to print the binary number of a given decimal number

belongs to collection: Rust Basic Programs

0

Here, we will create an 8-bit integer number and then we will print the corresponding binary number using format specifier in println!() macro.

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 print the binary number of a given decimal number is given below. The given program is compiled and executed successfully.

// Rust program to print the binary number 
// of a given decimal number

fn main()
{
    let num:i8 = 14;

    println!("Binary number is: {:#02b}", num);
}

Output:

Binary number is: 0b1110

Explanation:

Here, we created an 8-bit integer variable num with an initial value of 14. Then we printed the corresponding binary number using the ":#02b" format specifier in println!() macro.

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 print the octal number of a given ... >>
<< Rust program to print the hexadecimal number of th...