crypto_bigint/uint/boxed/
bit_not.rs1use super::BoxedUint;
4use crate::Limb;
5use core::ops::Not;
6
7impl BoxedUint {
8 #[must_use]
10 pub fn not(&self) -> Self {
11 let mut limbs = vec![Limb::ZERO; self.nlimbs()];
12
13 for i in 0..self.nlimbs() {
14 limbs[i] = self.limbs[i].not();
15 }
16
17 limbs.into()
18 }
19}
20
21impl Not for BoxedUint {
22 type Output = Self;
23
24 fn not(self) -> Self {
25 BoxedUint::not(&self)
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use crate::BoxedUint;
32
33 #[test]
34 fn bitnot_ok() {
35 assert_eq!(
36 BoxedUint::zero_with_precision(128).not(),
37 BoxedUint::max(128)
38 );
39 assert_eq!(
40 BoxedUint::max(128).not(),
41 BoxedUint::zero_with_precision(128)
42 );
43 }
44}