ADVERTISEMENT
ADVERTISEMENT

Rust program to check specific bit is HIGH (1) or LOW (0)

Here, we are going to learn how to check specific bit is HIGH (1) or LOW (0) 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 check 3rd bit of the number is HIGH (1) or LOW (0).

Program/Source Code:

The source code to check specific bit is HIGH (1) or LOW (0) is given below. The given program is compiled and executed successfully.

// Rust program to check specific 
// bit is HIGH or LOW

fn main()
{
    let num:i8 = 8;
    let mut res:i8 = 0;
    
    res = num & (1<<3);
    if res>0
    {
        println!("3rd bit is HIGH");
    }
    else
    {
        println!("3rd bit is LOW");
    }
}

Output:

3rd bit is HIGH

Explanation:

Here, we created an 8-bit integer variable num with an initial value of 8. Then we checked 3rd bit of the number is HIGH (1) or LOW (0) and printed the appropriate message.

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.