From 666378b14baeaaa6b717934656f7982c347e015e Mon Sep 17 00:00:00 2001 From: Adam Wick Date: Mon, 27 May 2019 21:41:05 -0700 Subject: [PATCH] Add support for bitwise and and or on unsigned numbers. --- src/unsigned/base.rs | 22 ++++++++++++++++++++++ src/unsigned/mod.rs | 1 + 2 files changed, 23 insertions(+) diff --git a/src/unsigned/base.rs b/src/unsigned/base.rs index 314fa82..82f36d3 100644 --- a/src/unsigned/base.rs +++ b/src/unsigned/base.rs @@ -89,6 +89,28 @@ macro_rules! generate_base $name{ value: x } } } + + impl BitOr for $name { + type Output = $name; + + fn bitor(mut self, rhs: Self) -> Self { + for (idx, val) in self.value.iter_mut().enumerate() { + *val |= rhs.value[idx]; + } + self + } + } + + impl BitAnd for $name { + type Output = $name; + + fn bitand(mut self, rhs: Self) -> Self { + for (idx, val) in self.value.iter_mut().enumerate() { + *val &= rhs.value[idx]; + } + self + } + } } } diff --git a/src/unsigned/mod.rs b/src/unsigned/mod.rs index 78c4d24..dcfe4f5 100644 --- a/src/unsigned/mod.rs +++ b/src/unsigned/mod.rs @@ -86,6 +86,7 @@ use std::ops::{Div,DivAssign}; use std::ops::{Rem,RemAssign}; use std::ops::{Shl,ShlAssign,Shr,ShrAssign}; use std::ops::{Sub,SubAssign}; +use std::ops::{BitAnd,BitOr}; use quickcheck::{Arbitrary,Gen};