pub struct Uint256(pub BigUint);
Tuple Fields
0: BigUint
Implementations
sourceimpl Uint256
impl Uint256
pub fn from_bytes_le(slice: &[u8]) -> Uint256
pub fn from_bytes_be(slice: &[u8]) -> Uint256
pub fn from_str_radix(s: &str, radix: u32) -> Result<Uint256, ParseBigIntError>
Methods from Deref<Target = BigUint>
sourcepub fn to_bytes_be(&self) -> Vec<u8, Global>
pub fn to_bytes_be(&self) -> Vec<u8, Global>
Returns the byte representation of the BigUint
in big-endian byte order.
Examples
use num_bigint::BigUint;
let i = BigUint::parse_bytes(b"1125", 10).unwrap();
assert_eq!(i.to_bytes_be(), vec![4, 101]);
sourcepub fn to_bytes_le(&self) -> Vec<u8, Global>
pub fn to_bytes_le(&self) -> Vec<u8, Global>
Returns the byte representation of the BigUint
in little-endian byte order.
Examples
use num_bigint::BigUint;
let i = BigUint::parse_bytes(b"1125", 10).unwrap();
assert_eq!(i.to_bytes_le(), vec![101, 4]);
sourcepub fn to_u32_digits(&self) -> Vec<u32, Global>
pub fn to_u32_digits(&self) -> Vec<u32, Global>
Returns the u32
digits representation of the BigUint
ordered least significant digit
first.
Examples
use num_bigint::BigUint;
assert_eq!(BigUint::from(1125u32).to_u32_digits(), vec![1125]);
assert_eq!(BigUint::from(4294967295u32).to_u32_digits(), vec![4294967295]);
assert_eq!(BigUint::from(4294967296u64).to_u32_digits(), vec![0, 1]);
assert_eq!(BigUint::from(112500000000u64).to_u32_digits(), vec![830850304, 26]);
sourcepub fn to_str_radix(&self, radix: u32) -> String
pub fn to_str_radix(&self, radix: u32) -> String
Returns the integer formatted as a string in the given radix.
radix
must be in the range 2...36
.
Examples
use num_bigint::BigUint;
let i = BigUint::parse_bytes(b"ff", 16).unwrap();
assert_eq!(i.to_str_radix(16), "ff");
sourcepub fn to_radix_be(&self, radix: u32) -> Vec<u8, Global>
pub fn to_radix_be(&self, radix: u32) -> Vec<u8, Global>
Returns the integer in the requested base in big-endian digit order.
The output is not given in a human readable alphabet but as a zero
based u8 number.
radix
must be in the range 2...256
.
Examples
use num_bigint::BigUint;
assert_eq!(BigUint::from(0xFFFFu64).to_radix_be(159),
vec![2, 94, 27]);
// 0xFFFF = 65535 = 2*(159^2) + 94*159 + 27
sourcepub fn to_radix_le(&self, radix: u32) -> Vec<u8, Global>
pub fn to_radix_le(&self, radix: u32) -> Vec<u8, Global>
Returns the integer in the requested base in little-endian digit order.
The output is not given in a human readable alphabet but as a zero
based u8 number.
radix
must be in the range 2...256
.
Examples
use num_bigint::BigUint;
assert_eq!(BigUint::from(0xFFFFu64).to_radix_le(159),
vec![27, 94, 2]);
// 0xFFFF = 65535 = 27 + 94*159 + 2*(159^2)
sourcepub fn modpow(&self, exponent: &BigUint, modulus: &BigUint) -> BigUint
pub fn modpow(&self, exponent: &BigUint, modulus: &BigUint) -> BigUint
Returns (self ^ exponent) % modulus
.
Panics if the modulus is zero.
sourcepub fn sqrt(&self) -> BigUint
pub fn sqrt(&self) -> BigUint
Returns the truncated principal square root of self
–
see Roots::sqrt
sourcepub fn cbrt(&self) -> BigUint
pub fn cbrt(&self) -> BigUint
Returns the truncated principal cube root of self
–
see Roots::cbrt.
sourcepub fn nth_root(&self, n: u32) -> BigUint
pub fn nth_root(&self, n: u32) -> BigUint
Returns the truncated principal n
th root of self
–
see Roots::nth_root.
Trait Implementations
sourceimpl<T> AddAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> AddAssign<T> for Uint256where
T: Into<Uint256>,
sourcefn add_assign(&mut self, v: T)
fn add_assign(&mut self, v: T)
+=
operation. Read moresourceimpl CheckedAdd for Uint256
impl CheckedAdd for Uint256
sourceimpl CheckedDiv for Uint256
impl CheckedDiv for Uint256
sourceimpl CheckedMul for Uint256
impl CheckedMul for Uint256
sourceimpl CheckedSub for Uint256
impl CheckedSub for Uint256
sourceimpl<'de> Deserialize<'de> for Uint256
impl<'de> Deserialize<'de> for Uint256
sourcefn deserialize<D>(deserializer: D) -> Result<Uint256, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Uint256, D::Error>where
D: Deserializer<'de>,
sourceimpl<T> DivAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> DivAssign<T> for Uint256where
T: Into<Uint256>,
sourcefn div_assign(&mut self, v: T)
fn div_assign(&mut self, v: T)
/=
operation. Read moresourceimpl<T> MulAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> MulAssign<T> for Uint256where
T: Into<Uint256>,
sourcefn mul_assign(&mut self, v: T)
fn mul_assign(&mut self, v: T)
*=
operation. Read moresourceimpl Ord for Uint256
impl Ord for Uint256
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Uint256> for Uint256
impl PartialOrd<Uint256> for Uint256
sourcefn partial_cmp(&self, other: &Uint256) -> Option<Ordering>
fn partial_cmp(&self, other: &Uint256) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<T> SubAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> SubAssign<T> for Uint256where
T: Into<Uint256>,
sourcefn sub_assign(&mut self, v: T)
fn sub_assign(&mut self, v: T)
-=
operation. Read more