Module malachite_base::num::logic::bit_iterable
source · Expand description
BitIterable
, a trait for producing a double-ended iterator over a
number’s bits.
§bits
use itertools::Itertools;
use malachite_base::num::logic::traits::BitIterable;
assert!(0u8.bits().next().is_none());
// 105 = 1101001b
assert_eq!(
105u32.bits().collect_vec(),
&[true, false, false, true, false, true, true]
);
assert!(0u8.bits().next_back().is_none());
// 105 = 1101001b
assert_eq!(
105u32.bits().rev().collect_vec(),
&[true, true, false, true, false, false, true]
);
assert_eq!(0i8.bits().next(), None);
// 105 = 01101001b, with a leading false bit to indicate sign
assert_eq!(
105i32.bits().collect_vec(),
&[true, false, false, true, false, true, true, false]
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
(-105i32).bits().collect_vec(),
&[true, true, true, false, true, false, false, true]
);
assert_eq!(0i8.bits().next_back(), None);
// 105 = 01101001b, with a leading false bit to indicate sign
assert_eq!(
105i32.bits().rev().collect_vec(),
&[false, true, true, false, true, false, false, true]
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
(-105i32).bits().rev().collect_vec(),
&[true, false, false, true, false, true, true, true]
);
Structs§
- A double-ended iterator over the bits of a signed primitive integer.
- A double-ended iterator over the bits of an unsigned primitive integer.