Q:

Rust program to clear specific bit using bitwise operator

belongs to collection: Rust Basic Programs

0

Here, we will create a 16-bit integer number and clear the 3rd bit of the number using the bitwise OR operator and bitwise NOT (!) operator, and print the result.

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 clear specific bits using the bitwise operator is given below. The given program is compiled and executed successfully.

// Rust program to clear specific bit 
// using bitwise operator

fn main() {
    let mut num:i16=10;    

    num = num & !(1<<3);

    println!("Result: {}",num);
}

Output:

Result: 2

Explanation:

Here, we created an integer variable num with an initial value of 10. Then we clear the 3rd bit of the number using the bitwise OR (|) and bitwise NOT (!) operator. After that, we printed the updated 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 convert a decimal number to a bina... >>
<< Rust program to set specific bit using bitwise ope...