[−][src]Struct ibig::UBig
Unsigned big integer.
Arbitrarily large unsigned integer.
Examples
let a = ubig!(a2a123bbb127779cccc123123ccc base 32); let b = ubig!(0x1231abcd4134); let c = UBig::from_str_radix("a2a123bbb127779cccc123123ccc", 32)?; let d = UBig::from_str_radix("1231abcd4134", 16)?; assert_eq!(a, c); assert_eq!(b, d); Ok::<(), ParseError>(())
Implementations
impl UBig
[src]
pub fn trailing_zeros(&self) -> Option<usize>
[src]
Returns the number of trailing zeros in the binary representation.
In other words, it is the smallest n
such that 2 to the power of n
divides the number.
For 0, it returns None
.
Examples
assert_eq!(ubig!(17).trailing_zeros(), Some(0)); assert_eq!(ubig!(48).trailing_zeros(), Some(4)); assert_eq!(ubig!(0b101000000).trailing_zeros(), Some(6)); assert_eq!(ubig!(0).trailing_zeros(), None);
pub fn ilog2(&self) -> Option<usize>
[src]
Integer logarithm base 2.
Returns the floor of the logarithm base 2 of the number. In other words, it is the position of the highest 1 bit in the binary representation.
For 0, it returns None
.
Examples
assert_eq!(ubig!(17).ilog2(), Some(4)); assert_eq!(ubig!(0b101000000).ilog2(), Some(8)); assert_eq!(ubig!(0).ilog2(), None);
impl UBig
[src]
pub fn from_le_bytes(bytes: &[u8]) -> UBig
[src]
Construct from little-endian bytes.
Examples
assert_eq!(UBig::from_le_bytes(&[3, 2, 1]), ubig!(0x010203));
pub fn from_be_bytes(bytes: &[u8]) -> UBig
[src]
Construct from big-endian bytes.
Examples
assert_eq!(UBig::from_be_bytes(&[1, 2, 3]), ubig!(0x010203));
pub fn to_le_bytes(&self) -> Vec<u8>
[src]
Return little-endian bytes.
Examples
assert!(ubig!(0).to_le_bytes().is_empty()); assert_eq!(ubig!(0x010203).to_le_bytes(), [3, 2, 1]);
pub fn to_be_bytes(&self) -> Vec<u8>
[src]
Return big-endian bytes.
Examples
assert!(ubig!(0).to_be_bytes().is_empty()); assert_eq!(ubig!(0x010203).to_be_bytes(), [1, 2, 3]);
impl UBig
[src]
pub fn in_radix(&self, radix: u32) -> InRadix<'_>
[src]
Representation in a given radix.
Panics
Panics radix
is not between 2 and 36 inclusive.
Examples
assert_eq!(format!("{}", ubig!(100).in_radix(2)), "1100100"); assert_eq!(format!("{}", ubig!(3000).in_radix(16)), "bb8"); assert_eq!(format!("{:#}", ubig!(3000).in_radix(16)), "BB8"); assert_eq!(format!("{:+010}", ubig!(100).in_radix(2)), "+001100100"); assert_eq!(format!("{:=^10}", ubig!(100).in_radix(2)), "=1100100=="); // For bases 2, 8, 10, 16 we don't have to use `in_radix`: assert_eq!(format!("{:x}", ubig!(3000)), "bb8");
pub fn to_str_radix(&self, radix: u32) -> String
[src]
String representation in an arbitrary radix.
Equivalent to self.to_radix(radix).to_string()
but more efficient.
Panics
Panics radix
is not between 2 and 36 inclusive.
Examples
assert_eq!(ubig!(0x123f).to_str_radix(16), "123f");
pub fn to_str_radix_uppercase(&self, radix: u32) -> String
[src]
impl UBig
[src]
pub fn from_str_radix(src: &str, radix: u32) -> Result<UBig, ParseError>
[src]
Convert a string in a given base to UBig
.
src
may contain an optional +
prefix.
Digits 10-35 are represented by a-z
or A-Z
.
Panics
Panics if radix
not in range 2-36.
Examples
assert_eq!(UBig::from_str_radix("+7ab", 32)?, ubig!(7499));
pub fn from_str_with_radix_prefix(src: &str) -> Result<UBig, ParseError>
[src]
Convert a string with an optional radix prefix to UBig
.
src
may contain an optional +
prefix.
Allowed prefixes: 0b
for binary, 0o
for octal, 0x
for hexadecimal.
Examples
assert_eq!(UBig::from_str_with_radix_prefix("+0o17")?, ubig!(0o17)); assert_eq!(UBig::from_str_with_radix_prefix("0x1f")?, ubig!(0x1f));
Trait Implementations
impl Binary for UBig
[src]
impl Clone for UBig
[src]
impl Debug for UBig
[src]
impl Eq for UBig
[src]
impl<'_> From<&'_ UBig> for IBig
[src]
impl From<UBig> for IBig
[src]
impl From<bool> for UBig
[src]
impl From<u128> for UBig
[src]
impl From<u16> for UBig
[src]
impl From<u32> for UBig
[src]
impl From<u64> for UBig
[src]
impl From<u8> for UBig
[src]
impl From<usize> for UBig
[src]
impl LowerHex for UBig
[src]
impl Octal for UBig
[src]
impl PartialEq<UBig> for UBig
[src]
impl StructuralEq for UBig
[src]
impl StructuralPartialEq for UBig
[src]
impl<'_> TryFrom<&'_ IBig> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(x: &IBig) -> Result<UBig, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for u8
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<u8, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for u16
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<u16, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for i128
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<i128, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for isize
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<isize, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for u32
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<u32, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for u64
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<u64, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for u128
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<u128, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for usize
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<usize, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for i8
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<i8, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for i16
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<i16, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for i32
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<i32, OutOfBoundsError>
[src]
impl<'_> TryFrom<&'_ UBig> for i64
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: &UBig) -> Result<i64, OutOfBoundsError>
[src]
impl TryFrom<IBig> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(x: IBig) -> Result<UBig, OutOfBoundsError>
[src]
impl TryFrom<UBig> for u8
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<u8, OutOfBoundsError>
[src]
impl TryFrom<UBig> for u16
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<u16, OutOfBoundsError>
[src]
impl TryFrom<UBig> for i128
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<i128, OutOfBoundsError>
[src]
impl TryFrom<UBig> for isize
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<isize, OutOfBoundsError>
[src]
impl TryFrom<UBig> for u32
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<u32, OutOfBoundsError>
[src]
impl TryFrom<UBig> for u64
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<u64, OutOfBoundsError>
[src]
impl TryFrom<UBig> for u128
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<u128, OutOfBoundsError>
[src]
impl TryFrom<UBig> for usize
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<usize, OutOfBoundsError>
[src]
impl TryFrom<UBig> for i8
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<i8, OutOfBoundsError>
[src]
impl TryFrom<UBig> for i16
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<i16, OutOfBoundsError>
[src]
impl TryFrom<UBig> for i32
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<i32, OutOfBoundsError>
[src]
impl TryFrom<UBig> for i64
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: UBig) -> Result<i64, OutOfBoundsError>
[src]
impl TryFrom<i128> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: i128) -> Result<UBig, OutOfBoundsError>
[src]
impl TryFrom<i16> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: i16) -> Result<UBig, OutOfBoundsError>
[src]
impl TryFrom<i32> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: i32) -> Result<UBig, OutOfBoundsError>
[src]
impl TryFrom<i64> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: i64) -> Result<UBig, OutOfBoundsError>
[src]
impl TryFrom<i8> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: i8) -> Result<UBig, OutOfBoundsError>
[src]
impl TryFrom<isize> for UBig
[src]
type Error = OutOfBoundsError
The type returned in the event of a conversion error.
pub fn try_from(value: isize) -> Result<UBig, OutOfBoundsError>
[src]
impl UpperHex for UBig
[src]
Auto Trait Implementations
impl RefUnwindSafe for UBig
impl Send for UBig
impl Sync for UBig
impl Unpin for UBig
impl UnwindSafe for UBig
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,