malachite_nz/integer/logic/low_mask.rs
1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::integer::Integer;
10use crate::natural::Natural;
11use malachite_base::num::logic::traits::LowMask;
12
13impl LowMask for Integer {
14 /// Returns an [`Integer`] whose least significant $b$ bits are `true` and whose other bits are
15 /// `false`.
16 ///
17 /// $f(b) = 2^b - 1$.
18 ///
19 /// # Worst-case complexity
20 /// $T(n) = O(n)$
21 ///
22 /// $M(n) = O(n)$
23 ///
24 /// where $T$ is time, $M$ is additional memory, and $n$ is `bits`.
25 ///
26 /// # Examples
27 /// ```
28 /// use malachite_base::num::logic::traits::LowMask;
29 /// use malachite_nz::integer::Integer;
30 ///
31 /// assert_eq!(Integer::low_mask(0), 0);
32 /// assert_eq!(Integer::low_mask(3), 7);
33 /// assert_eq!(
34 /// Integer::low_mask(100).to_string(),
35 /// "1267650600228229401496703205375"
36 /// );
37 /// ```
38 #[inline]
39 fn low_mask(bits: u64) -> Integer {
40 Integer::from(Natural::low_mask(bits))
41 }
42}