pub trait BigInteger:
'static
+ Copy
+ Clone
+ Debug
+ Default
+ Display
+ Eq
+ Ord
+ Send
+ Sized
+ Sync
+ Zeroize
+ From<u128>
+ From<u64>
+ From<u32>
+ From<u16>
+ From<u8>
+ BitXorAssign<Self>
+ for<'a> BitXorAssign<&'a Self>
+ BitXor<Self, Output = Self>
+ for<'a> BitXor<&'a Self, Output = Self>
+ BitAndAssign<Self>
+ for<'a> BitAndAssign<&'a Self>
+ BitAnd<Self, Output = Self>
+ for<'a> BitAnd<&'a Self, Output = Self>
+ BitOrAssign<Self>
+ for<'a> BitOrAssign<&'a Self>
+ BitOr<Self, Output = Self>
+ for<'a> BitOr<&'a Self, Output = Self>
+ Shr<u32, Output = Self>
+ ShrAssign<u32>
+ Shl<u32, Output = Self>
+ ShlAssign<u32>
+ BitIteratorBE {
const NUM_LIMBS: usize;
const LIMB_BITS: usize;
const MAX: Self;
const ONE: Self;
const ZERO: Self;
const BITS: usize = _;
const BYTES: usize = _;
// Required methods
fn is_odd(&self) -> bool;
fn is_even(&self) -> bool;
fn is_zero(&self) -> bool;
fn num_bits(&self) -> usize;
fn get_bit(&self, i: usize) -> bool;
fn from_bytes_le(bytes: &[u8]) -> Self;
fn into_bytes_le(self) -> Vec<u8> ⓘ;
}Expand description
Defines a big integer with a constant length.
Required Associated Constants§
Provided Associated Constants§
Required Methods§
Sourcefn is_odd(&self) -> bool
fn is_odd(&self) -> bool
Returns true if this number is odd.
§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};
let mut one = U64::from(1u64);
assert!(one.is_odd());Sourcefn is_even(&self) -> bool
fn is_even(&self) -> bool
Returns true if this number is even.
§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};
let mut two = U64::from(2u64);
assert!(two.is_even());Sourcefn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Returns true if this number is zero.
§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};
let mut zero = U64::from(0u64);
assert!(zero.is_zero());Sourcefn num_bits(&self) -> usize
fn num_bits(&self) -> usize
Return the minimum number of bits needed to encode this number.
One bit is necessary to encode zero.
§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};
let zero = U64::from(0u64);
assert_eq!(zero.num_bits(), 1);
let one = U64::from(1u64);
assert_eq!(one.num_bits(), 1);
let max = U64::from(u64::MAX);
assert_eq!(max.num_bits(), 64);
let u32_max = U64::from(u32::MAX as u64);
assert_eq!(u32_max.num_bits(), 32);Sourcefn get_bit(&self, i: usize) -> bool
fn get_bit(&self, i: usize) -> bool
Find the i-th bit of self.
§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};
let mut one = U64::from(1u64);
assert!(one.get_bit(0));
assert!(!one.get_bit(1));Sourcefn from_bytes_le(bytes: &[u8]) -> Self
fn from_bytes_le(bytes: &[u8]) -> Self
Sourcefn into_bytes_le(self) -> Vec<u8> ⓘ
fn into_bytes_le(self) -> Vec<u8> ⓘ
Convert bigint to little-endian bytes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.