diff options
-rw-r--r-- | src/block.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/block.rs b/src/block.rs index e9ba527..3a9eea2 100644 --- a/src/block.rs +++ b/src/block.rs @@ -41,17 +41,11 @@ impl Block { } /// Clip the block by setting all bits beyond the given length to 0. - pub fn clip(&self, mut length: usize) -> Block { - let mut block = self.0; - for byte in &mut block { - if length == 0 { - *byte = 0; - } else if length < 8 { - *byte &= 0xff << (8 - length); - } - length = length.saturating_sub(8); + pub fn clip(&self, length: usize) -> Block { + match length { + 0 => Block::default(), + _ => Block::from_int(self.to_int() & (u128::MAX << (128 - length))), } - Block(block) } /// Computes self * 2^exponent |