pub struct Uint256(pub BigUint);
Tuple Fields§
§0: BigUint
Implementations§
source§impl 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§
source§impl<T> AddAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> AddAssign<T> for Uint256where
T: Into<Uint256>,
source§fn add_assign(&mut self, v: T)
fn add_assign(&mut self, v: T)
+=
operation. Read moresource§impl CheckedAdd for Uint256
impl CheckedAdd for Uint256
source§impl CheckedDiv for Uint256
impl CheckedDiv for Uint256
source§impl CheckedMul for Uint256
impl CheckedMul for Uint256
source§impl CheckedSub for Uint256
impl CheckedSub for Uint256
source§impl<'de> Deserialize<'de> for Uint256
impl<'de> Deserialize<'de> for Uint256
source§fn 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>,
source§impl<T> DivAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> DivAssign<T> for Uint256where
T: Into<Uint256>,
source§fn div_assign(&mut self, v: T)
fn div_assign(&mut self, v: T)
/=
operation. Read moresource§impl<T> MulAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> MulAssign<T> for Uint256where
T: Into<Uint256>,
source§fn mul_assign(&mut self, v: T)
fn mul_assign(&mut self, v: T)
*=
operation. Read moresource§impl Ord for Uint256
impl Ord for Uint256
source§impl PartialOrd<Uint256> for Uint256
impl PartialOrd<Uint256> for Uint256
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<T> SubAssign<T> for Uint256where
T: Into<Uint256>,
impl<T> SubAssign<T> for Uint256where
T: Into<Uint256>,
source§fn sub_assign(&mut self, v: T)
fn sub_assign(&mut self, v: T)
-=
operation. Read more