Skip to content

Commit

Permalink
feat: to_u32
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWOLAND committed Dec 1, 2023
1 parent a88bb34 commit c7f05bd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ impl BigInt {
let is_odd: bool = self.v.retrieve().bit(0).into();
!is_odd
}

pub fn to_u32(&self) -> Result<u32, String> {
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<u16> for BigInt {
Expand Down

0 comments on commit c7f05bd

Please sign in to comment.