The source code to set specific bits using the bitwise operator is given below. The given program is compiled and executed successfully.
// Rust program to set specific bit
// using bitwise operator
fn main() {
let mut num:i16 = 2;
num = num | (1<<3);
println!("Number after setting 3rd bit: {}",num);
}
Output:
Number after setting 3rd bit: 10
Explanation:
Here, we created an integer variable num with an initial value of 2. Then we set the 3rd bit of the number using the bitwise OR (|) operator. After that, we printed the updated number.
Program/Source Code:
The source code to set specific bits using the bitwise operator is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created an integer variable num with an initial value of 2. Then we set the 3rd bit of the number using the bitwise OR (|) operator. After that, we printed the updated number.
need an explanation for this answer? contact us directly to get an explanation for this answer