The source code to count the total number of trailing zeros is given below. The given program is compiled and executed successfully.
// Rust program to count the
// total number of trailing zeros
fn main() {
let mut num:i16 = 12;
let mut val:i16 = 0;
let mut tmp:i16 = 0;
while val<16
{
tmp = num & (1<<val);
if tmp>0
{
break;
}
val = val + 1;
}
println!("Total number of trailing 0's are: {}",val);
}
Output:
Total number of trailing 0's are: 2
Explanation:
Here, we created a 16-bit integer variable num with an initial value of 12. Then we counted the total number of trailing zeros using bitwise operators and printed the result.
Program/Source Code:
The source code to count the total number of trailing zeros is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created a 16-bit integer variable num with an initial value of 12. Then we counted the total number of trailing zeros using bitwise operators and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer