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.
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.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer