ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to learn how to print the binary number of a given decimal number in Rust programming language?
Submitted by Nidhi, on September 24, 2021

Problem Solution:

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

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.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.