Skip to main content

is_power_of_two

Function is_power_of_two 

Source
pub fn is_power_of_two(n: u64) -> bool
Expand description

n ikkining darajasimi? (1, 2, 4, 8, …)

G’oya: ikkining darajasida faqat bitta 1 bit bor, shuning uchun n & (n - 1) == 0.

§Misol

use rust_algorithms::numbers::is_power_of_two;

assert!(is_power_of_two(64));
assert!(!is_power_of_two(0));
assert!(!is_power_of_two(48));