How to count zeros in binary number with Rust

2 Answers

0 votes
fn main() {
    let n = 0b01101101u8;
 
    println!("{}", n.count_zeros());
}
  
  
  
  
/*
run:
  
3
  
*/

 



answered Nov 5, 2022 by avibootz
0 votes
fn main() {
    let n:i16 = 14; // 1110
 
    println!("{}", n.count_zeros());
}
  
  
  
  
/*
run:
  
13
  
*/

 



answered Nov 5, 2022 by avibootz
...