Module malachite_base::num::conversion::digits::power_of_2_digit_iterable
source · Expand description
PowerOf2DigitIterable
, a trait for producing
PrimitivePowerOf2DigitIterator
, a
double-ended iterator for iterating over a number’s base-$2^k$ digits.
§power_of_2_digits
use itertools::Itertools;
use malachite_base::num::conversion::traits::PowerOf2DigitIterable;
let mut digits = PowerOf2DigitIterable::<u8>::power_of_2_digits(0u8, 2);
assert!(digits.next().is_none());
// 107 = 1101011b
let digits = PowerOf2DigitIterable::<u8>::power_of_2_digits(107u32, 2);
assert_eq!(digits.collect_vec(), &[3, 2, 2, 1]);
let mut digits = PowerOf2DigitIterable::<u8>::power_of_2_digits(0u8, 2);
assert!(digits.next_back().is_none());
// 107 = 1101011b
let digits = PowerOf2DigitIterable::<u8>::power_of_2_digits(107u32, 2);
assert_eq!(digits.rev().collect_vec(), &[1, 2, 2, 3]);
Structs§
- A double-ended iterator over the base-$2^k$ digits of an unsigned primitive integer.