diff --git a/src/numbers.rs b/src/numbers.rs index 2a7ad4d..712f1f5 100644 --- a/src/numbers.rs +++ b/src/numbers.rs @@ -120,6 +120,14 @@ impl BigInt { let is_odd: bool = self.v.retrieve().bit(0).into(); !is_odd } + + pub fn to_u32(&self) -> Result { + let ret = self.v.retrieve().as_words()[0] as u32; + if BigInt::from(ret) != *self { + return Err(format!("Overflow error -- {} exceeds u32 size limits", self).to_string()); + } + Ok(ret) + } } impl From for BigInt {