[−][src]Trait num_traits::int::PrimInt
Required Methods
fn count_ones(self) -> u32
Returns the number of ones in the binary representation of self.
Examples
use num_traits::PrimInt; let n = 0b01001100u8; assert_eq!(n.count_ones(), 3);
fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation of self.
Examples
use num_traits::PrimInt; let n = 0b01001100u8; assert_eq!(n.count_zeros(), 5);
fn leading_zeros(self) -> u32
Returns the number of leading zeros in the binary representation
of self.
Examples
use num_traits::PrimInt; let n = 0b0101000u16; assert_eq!(n.leading_zeros(), 10);
fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation
of self.
Examples
use num_traits::PrimInt; let n = 0b0101000u16; assert_eq!(n.trailing_zeros(), 3);
fn rotate_left(self, n: u32) -> Self
Shifts the bits to the left by a specified amount amount, n, wrapping
the truncated bits to the end of the resulting integer.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; let m = 0x3456789ABCDEF012u64; assert_eq!(n.rotate_left(12), m);
fn rotate_right(self, n: u32) -> Self
Shifts the bits to the right by a specified amount amount, n, wrapping
the truncated bits to the beginning of the resulting integer.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; let m = 0xDEF0123456789ABCu64; assert_eq!(n.rotate_right(12), m);
fn signed_shl(self, n: u32) -> Self
Shifts the bits to the left by a specified amount amount, n, filling
zeros in the least significant bits.
This is bitwise equivalent to signed Shl.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; let m = 0x3456789ABCDEF000u64; assert_eq!(n.signed_shl(12), m);
fn signed_shr(self, n: u32) -> Self
Shifts the bits to the right by a specified amount amount, n, copying
the "sign bit" in the most significant bits even for unsigned types.
This is bitwise equivalent to signed Shr.
Examples
use num_traits::PrimInt; let n = 0xFEDCBA9876543210u64; let m = 0xFFFFEDCBA9876543u64; assert_eq!(n.signed_shr(12), m);
fn unsigned_shl(self, n: u32) -> Self
Shifts the bits to the left by a specified amount amount, n, filling
zeros in the least significant bits.
This is bitwise equivalent to unsigned Shl.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFi64; let m = 0x3456789ABCDEF000i64; assert_eq!(n.unsigned_shl(12), m);
fn unsigned_shr(self, n: u32) -> Self
Shifts the bits to the right by a specified amount amount, n, filling
zeros in the most significant bits.
This is bitwise equivalent to unsigned Shr.
Examples
use num_traits::PrimInt; let n = 0xFEDCBA9876543210i64; let m = 0x000FEDCBA9876543i64; assert_eq!(n.unsigned_shr(12), m);
fn swap_bytes(self) -> Self
Reverses the byte order of the integer.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; let m = 0xEFCDAB8967452301u64; assert_eq!(n.swap_bytes(), m);
fn from_be(x: Self) -> Self
Convert an integer from big endian to the target's endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; if cfg!(target_endian = "big") { assert_eq!(u64::from_be(n), n) } else { assert_eq!(u64::from_be(n), n.swap_bytes()) }
fn from_le(x: Self) -> Self
Convert an integer from little endian to the target's endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; if cfg!(target_endian = "little") { assert_eq!(u64::from_le(n), n) } else { assert_eq!(u64::from_le(n), n.swap_bytes()) }
fn to_be(self) -> Self
Convert self to big endian from the target's endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; if cfg!(target_endian = "big") { assert_eq!(n.to_be(), n) } else { assert_eq!(n.to_be(), n.swap_bytes()) }
fn to_le(self) -> Self
Convert self to little endian from the target's endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
Examples
use num_traits::PrimInt; let n = 0x0123456789ABCDEFu64; if cfg!(target_endian = "little") { assert_eq!(n.to_le(), n) } else { assert_eq!(n.to_le(), n.swap_bytes()) }
fn pow(self, exp: u32) -> Self
Raises self to the power of exp, using exponentiation by squaring.
Examples
use num_traits::PrimInt; assert_eq!(2i32.pow(4), 16);
Implementations on Foreign Types
impl PrimInt for u8[src]
impl PrimInt for u8fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> u8[src]
fn rotate_left(self, n: u32) -> u8fn rotate_right(self, n: u32) -> u8[src]
fn rotate_right(self, n: u32) -> u8fn signed_shl(self, n: u32) -> u8[src]
fn signed_shl(self, n: u32) -> u8fn signed_shr(self, n: u32) -> u8[src]
fn signed_shr(self, n: u32) -> u8fn unsigned_shl(self, n: u32) -> u8[src]
fn unsigned_shl(self, n: u32) -> u8fn unsigned_shr(self, n: u32) -> u8[src]
fn unsigned_shr(self, n: u32) -> u8fn swap_bytes(self) -> u8[src]
fn swap_bytes(self) -> u8fn from_be(x: u8) -> u8[src]
fn from_be(x: u8) -> u8fn from_le(x: u8) -> u8[src]
fn from_le(x: u8) -> u8fn to_be(self) -> u8[src]
fn to_be(self) -> u8fn to_le(self) -> u8[src]
fn to_le(self) -> u8fn pow(self, exp: u32) -> u8[src]
fn pow(self, exp: u32) -> u8impl PrimInt for u16[src]
impl PrimInt for u16fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> u16[src]
fn rotate_left(self, n: u32) -> u16fn rotate_right(self, n: u32) -> u16[src]
fn rotate_right(self, n: u32) -> u16fn signed_shl(self, n: u32) -> u16[src]
fn signed_shl(self, n: u32) -> u16fn signed_shr(self, n: u32) -> u16[src]
fn signed_shr(self, n: u32) -> u16fn unsigned_shl(self, n: u32) -> u16[src]
fn unsigned_shl(self, n: u32) -> u16fn unsigned_shr(self, n: u32) -> u16[src]
fn unsigned_shr(self, n: u32) -> u16fn swap_bytes(self) -> u16[src]
fn swap_bytes(self) -> u16fn from_be(x: u16) -> u16[src]
fn from_be(x: u16) -> u16fn from_le(x: u16) -> u16[src]
fn from_le(x: u16) -> u16fn to_be(self) -> u16[src]
fn to_be(self) -> u16fn to_le(self) -> u16[src]
fn to_le(self) -> u16fn pow(self, exp: u32) -> u16[src]
fn pow(self, exp: u32) -> u16impl PrimInt for usize[src]
impl PrimInt for usizefn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> usize[src]
fn rotate_left(self, n: u32) -> usizefn rotate_right(self, n: u32) -> usize[src]
fn rotate_right(self, n: u32) -> usizefn signed_shl(self, n: u32) -> usize[src]
fn signed_shl(self, n: u32) -> usizefn signed_shr(self, n: u32) -> usize[src]
fn signed_shr(self, n: u32) -> usizefn unsigned_shl(self, n: u32) -> usize[src]
fn unsigned_shl(self, n: u32) -> usizefn unsigned_shr(self, n: u32) -> usize[src]
fn unsigned_shr(self, n: u32) -> usizefn swap_bytes(self) -> usize[src]
fn swap_bytes(self) -> usizefn from_be(x: usize) -> usize[src]
fn from_be(x: usize) -> usizefn from_le(x: usize) -> usize[src]
fn from_le(x: usize) -> usizefn to_be(self) -> usize[src]
fn to_be(self) -> usizefn to_le(self) -> usize[src]
fn to_le(self) -> usizefn pow(self, exp: u32) -> usize[src]
fn pow(self, exp: u32) -> usizeimpl PrimInt for u64[src]
impl PrimInt for u64fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> u64[src]
fn rotate_left(self, n: u32) -> u64fn rotate_right(self, n: u32) -> u64[src]
fn rotate_right(self, n: u32) -> u64fn signed_shl(self, n: u32) -> u64[src]
fn signed_shl(self, n: u32) -> u64fn signed_shr(self, n: u32) -> u64[src]
fn signed_shr(self, n: u32) -> u64fn unsigned_shl(self, n: u32) -> u64[src]
fn unsigned_shl(self, n: u32) -> u64fn unsigned_shr(self, n: u32) -> u64[src]
fn unsigned_shr(self, n: u32) -> u64fn swap_bytes(self) -> u64[src]
fn swap_bytes(self) -> u64fn from_be(x: u64) -> u64[src]
fn from_be(x: u64) -> u64fn from_le(x: u64) -> u64[src]
fn from_le(x: u64) -> u64fn to_be(self) -> u64[src]
fn to_be(self) -> u64fn to_le(self) -> u64[src]
fn to_le(self) -> u64fn pow(self, exp: u32) -> u64[src]
fn pow(self, exp: u32) -> u64impl PrimInt for i16[src]
impl PrimInt for i16fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> i16[src]
fn rotate_left(self, n: u32) -> i16fn rotate_right(self, n: u32) -> i16[src]
fn rotate_right(self, n: u32) -> i16fn signed_shl(self, n: u32) -> i16[src]
fn signed_shl(self, n: u32) -> i16fn signed_shr(self, n: u32) -> i16[src]
fn signed_shr(self, n: u32) -> i16fn unsigned_shl(self, n: u32) -> i16[src]
fn unsigned_shl(self, n: u32) -> i16fn unsigned_shr(self, n: u32) -> i16[src]
fn unsigned_shr(self, n: u32) -> i16fn swap_bytes(self) -> i16[src]
fn swap_bytes(self) -> i16fn from_be(x: i16) -> i16[src]
fn from_be(x: i16) -> i16fn from_le(x: i16) -> i16[src]
fn from_le(x: i16) -> i16fn to_be(self) -> i16[src]
fn to_be(self) -> i16fn to_le(self) -> i16[src]
fn to_le(self) -> i16fn pow(self, exp: u32) -> i16[src]
fn pow(self, exp: u32) -> i16impl PrimInt for i128[src]
impl PrimInt for i128fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> i128[src]
fn rotate_left(self, n: u32) -> i128fn rotate_right(self, n: u32) -> i128[src]
fn rotate_right(self, n: u32) -> i128fn signed_shl(self, n: u32) -> i128[src]
fn signed_shl(self, n: u32) -> i128fn signed_shr(self, n: u32) -> i128[src]
fn signed_shr(self, n: u32) -> i128fn unsigned_shl(self, n: u32) -> i128[src]
fn unsigned_shl(self, n: u32) -> i128fn unsigned_shr(self, n: u32) -> i128[src]
fn unsigned_shr(self, n: u32) -> i128fn swap_bytes(self) -> i128[src]
fn swap_bytes(self) -> i128fn from_be(x: i128) -> i128[src]
fn from_be(x: i128) -> i128fn from_le(x: i128) -> i128[src]
fn from_le(x: i128) -> i128fn to_be(self) -> i128[src]
fn to_be(self) -> i128fn to_le(self) -> i128[src]
fn to_le(self) -> i128fn pow(self, exp: u32) -> i128[src]
fn pow(self, exp: u32) -> i128impl PrimInt for i8[src]
impl PrimInt for i8fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> i8[src]
fn rotate_left(self, n: u32) -> i8fn rotate_right(self, n: u32) -> i8[src]
fn rotate_right(self, n: u32) -> i8fn signed_shl(self, n: u32) -> i8[src]
fn signed_shl(self, n: u32) -> i8fn signed_shr(self, n: u32) -> i8[src]
fn signed_shr(self, n: u32) -> i8fn unsigned_shl(self, n: u32) -> i8[src]
fn unsigned_shl(self, n: u32) -> i8fn unsigned_shr(self, n: u32) -> i8[src]
fn unsigned_shr(self, n: u32) -> i8fn swap_bytes(self) -> i8[src]
fn swap_bytes(self) -> i8fn from_be(x: i8) -> i8[src]
fn from_be(x: i8) -> i8fn from_le(x: i8) -> i8[src]
fn from_le(x: i8) -> i8fn to_be(self) -> i8[src]
fn to_be(self) -> i8fn to_le(self) -> i8[src]
fn to_le(self) -> i8fn pow(self, exp: u32) -> i8[src]
fn pow(self, exp: u32) -> i8impl PrimInt for i32[src]
impl PrimInt for i32fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> i32[src]
fn rotate_left(self, n: u32) -> i32fn rotate_right(self, n: u32) -> i32[src]
fn rotate_right(self, n: u32) -> i32fn signed_shl(self, n: u32) -> i32[src]
fn signed_shl(self, n: u32) -> i32fn signed_shr(self, n: u32) -> i32[src]
fn signed_shr(self, n: u32) -> i32fn unsigned_shl(self, n: u32) -> i32[src]
fn unsigned_shl(self, n: u32) -> i32fn unsigned_shr(self, n: u32) -> i32[src]
fn unsigned_shr(self, n: u32) -> i32fn swap_bytes(self) -> i32[src]
fn swap_bytes(self) -> i32fn from_be(x: i32) -> i32[src]
fn from_be(x: i32) -> i32fn from_le(x: i32) -> i32[src]
fn from_le(x: i32) -> i32fn to_be(self) -> i32[src]
fn to_be(self) -> i32fn to_le(self) -> i32[src]
fn to_le(self) -> i32fn pow(self, exp: u32) -> i32[src]
fn pow(self, exp: u32) -> i32impl PrimInt for u128[src]
impl PrimInt for u128fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> u128[src]
fn rotate_left(self, n: u32) -> u128fn rotate_right(self, n: u32) -> u128[src]
fn rotate_right(self, n: u32) -> u128fn signed_shl(self, n: u32) -> u128[src]
fn signed_shl(self, n: u32) -> u128fn signed_shr(self, n: u32) -> u128[src]
fn signed_shr(self, n: u32) -> u128fn unsigned_shl(self, n: u32) -> u128[src]
fn unsigned_shl(self, n: u32) -> u128fn unsigned_shr(self, n: u32) -> u128[src]
fn unsigned_shr(self, n: u32) -> u128fn swap_bytes(self) -> u128[src]
fn swap_bytes(self) -> u128fn from_be(x: u128) -> u128[src]
fn from_be(x: u128) -> u128fn from_le(x: u128) -> u128[src]
fn from_le(x: u128) -> u128fn to_be(self) -> u128[src]
fn to_be(self) -> u128fn to_le(self) -> u128[src]
fn to_le(self) -> u128fn pow(self, exp: u32) -> u128[src]
fn pow(self, exp: u32) -> u128impl PrimInt for isize[src]
impl PrimInt for isizefn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> isize[src]
fn rotate_left(self, n: u32) -> isizefn rotate_right(self, n: u32) -> isize[src]
fn rotate_right(self, n: u32) -> isizefn signed_shl(self, n: u32) -> isize[src]
fn signed_shl(self, n: u32) -> isizefn signed_shr(self, n: u32) -> isize[src]
fn signed_shr(self, n: u32) -> isizefn unsigned_shl(self, n: u32) -> isize[src]
fn unsigned_shl(self, n: u32) -> isizefn unsigned_shr(self, n: u32) -> isize[src]
fn unsigned_shr(self, n: u32) -> isizefn swap_bytes(self) -> isize[src]
fn swap_bytes(self) -> isizefn from_be(x: isize) -> isize[src]
fn from_be(x: isize) -> isizefn from_le(x: isize) -> isize[src]
fn from_le(x: isize) -> isizefn to_be(self) -> isize[src]
fn to_be(self) -> isizefn to_le(self) -> isize[src]
fn to_le(self) -> isizefn pow(self, exp: u32) -> isize[src]
fn pow(self, exp: u32) -> isizeimpl PrimInt for i64[src]
impl PrimInt for i64fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> i64[src]
fn rotate_left(self, n: u32) -> i64fn rotate_right(self, n: u32) -> i64[src]
fn rotate_right(self, n: u32) -> i64fn signed_shl(self, n: u32) -> i64[src]
fn signed_shl(self, n: u32) -> i64fn signed_shr(self, n: u32) -> i64[src]
fn signed_shr(self, n: u32) -> i64fn unsigned_shl(self, n: u32) -> i64[src]
fn unsigned_shl(self, n: u32) -> i64fn unsigned_shr(self, n: u32) -> i64[src]
fn unsigned_shr(self, n: u32) -> i64fn swap_bytes(self) -> i64[src]
fn swap_bytes(self) -> i64fn from_be(x: i64) -> i64[src]
fn from_be(x: i64) -> i64fn from_le(x: i64) -> i64[src]
fn from_le(x: i64) -> i64fn to_be(self) -> i64[src]
fn to_be(self) -> i64fn to_le(self) -> i64[src]
fn to_le(self) -> i64fn pow(self, exp: u32) -> i64[src]
fn pow(self, exp: u32) -> i64impl PrimInt for u32[src]
impl PrimInt for u32fn count_ones(self) -> u32[src]
fn count_ones(self) -> u32fn count_zeros(self) -> u32[src]
fn count_zeros(self) -> u32fn leading_zeros(self) -> u32[src]
fn leading_zeros(self) -> u32fn trailing_zeros(self) -> u32[src]
fn trailing_zeros(self) -> u32fn rotate_left(self, n: u32) -> u32[src]
fn rotate_left(self, n: u32) -> u32fn rotate_right(self, n: u32) -> u32[src]
fn rotate_right(self, n: u32) -> u32fn signed_shl(self, n: u32) -> u32[src]
fn signed_shl(self, n: u32) -> u32fn signed_shr(self, n: u32) -> u32[src]
fn signed_shr(self, n: u32) -> u32fn unsigned_shl(self, n: u32) -> u32[src]
fn unsigned_shl(self, n: u32) -> u32fn unsigned_shr(self, n: u32) -> u32[src]
fn unsigned_shr(self, n: u32) -> u32fn swap_bytes(self) -> u32[src]
fn swap_bytes(self) -> u32fn from_be(x: u32) -> u32[src]
fn from_be(x: u32) -> u32fn from_le(x: u32) -> u32[src]
fn from_le(x: u32) -> u32fn to_be(self) -> u32[src]
fn to_be(self) -> u32fn to_le(self) -> u32[src]
fn to_le(self) -> u32fn pow(self, exp: u32) -> u32[src]
fn pow(self, exp: u32) -> u32