Contact: aviboots(AT)netvision.net.il
39,851 questions
51,772 answers
573 users
fn round_to_next_power_of_2(n: u32) -> u32 { if n == 0 { 1 } else { 2u32.pow((n as f64).log2().ceil() as u32) } } fn main() { let num = 21; println!("Next power of 2: {}", round_to_next_power_of_2(num)); } /* run: Next power of 2: 32 */