Trait malachite_base::num::logic::traits::BitConvertible

source ·
pub trait BitConvertible {
    // Required methods
    fn to_bits_asc(&self) -> Vec<bool>;
    fn to_bits_desc(&self) -> Vec<bool>;
    fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> Self;
    fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> Self;
}
Expand description

Defines functions that express a number as a Vec of bits or construct a number from an iterator of bits.

Required Methods§

source

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

source

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

source

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> Self

Converts an iterator of bits into a number. The input bits are in ascending order: least- to most-significant.

source

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> Self

Converts an iterator of bits into a value. The input bits are in descending order: most- to least-significant.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl BitConvertible for i8

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, the last bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, the first bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> i8

Converts an iterator of bits into a value. The bits should be in ascending order (least- to most-significant).

The bits are interpreted as in twos-complement, and the last bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that doesn’t fit in the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> i8

Converts an iterator of bits into a value. The bits should be in descending order (most- to least-significant).

The bits are interpreted as in twos-complement, and the first bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

If bits is empty or $b_0$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§Examples

See here.

source§

impl BitConvertible for i16

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, the last bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, the first bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> i16

Converts an iterator of bits into a value. The bits should be in ascending order (least- to most-significant).

The bits are interpreted as in twos-complement, and the last bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that doesn’t fit in the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> i16

Converts an iterator of bits into a value. The bits should be in descending order (most- to least-significant).

The bits are interpreted as in twos-complement, and the first bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

If bits is empty or $b_0$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§Examples

See here.

source§

impl BitConvertible for i32

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, the last bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, the first bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> i32

Converts an iterator of bits into a value. The bits should be in ascending order (least- to most-significant).

The bits are interpreted as in twos-complement, and the last bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that doesn’t fit in the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> i32

Converts an iterator of bits into a value. The bits should be in descending order (most- to least-significant).

The bits are interpreted as in twos-complement, and the first bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

If bits is empty or $b_0$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§Examples

See here.

source§

impl BitConvertible for i64

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, the last bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, the first bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> i64

Converts an iterator of bits into a value. The bits should be in ascending order (least- to most-significant).

The bits are interpreted as in twos-complement, and the last bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that doesn’t fit in the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> i64

Converts an iterator of bits into a value. The bits should be in descending order (most- to least-significant).

The bits are interpreted as in twos-complement, and the first bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

If bits is empty or $b_0$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§Examples

See here.

source§

impl BitConvertible for i128

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, the last bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, the first bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> i128

Converts an iterator of bits into a value. The bits should be in ascending order (least- to most-significant).

The bits are interpreted as in twos-complement, and the last bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that doesn’t fit in the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> i128

Converts an iterator of bits into a value. The bits should be in descending order (most- to least-significant).

The bits are interpreted as in twos-complement, and the first bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

If bits is empty or $b_0$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§Examples

See here.

source§

impl BitConvertible for isize

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, the last bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, the first bit is the sign bit: false if the number is non-negative and true if it is negative.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> isize

Converts an iterator of bits into a value. The bits should be in ascending order (least- to most-significant).

The bits are interpreted as in twos-complement, and the last bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that doesn’t fit in the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> isize

Converts an iterator of bits into a value. The bits should be in descending order (most- to least-significant).

The bits are interpreted as in twos-complement, and the first bit is the sign bit; if it is false, the number is non-negative, and if it is true, the number is negative.

The function panics if the input represents a number that can’t fit in the output type.

If bits is empty or $b_0$ is false, then $$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§Examples

See here.

source§

impl BitConvertible for u8

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, it ends with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, it begins with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> u8

Converts an iterator of bits into a number. The bits should be in ascending order (least- to most-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> u8

Converts an iterator of bits into a number. The bits should be in descending order (most- to least-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

impl BitConvertible for u16

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, it ends with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, it begins with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> u16

Converts an iterator of bits into a number. The bits should be in ascending order (least- to most-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> u16

Converts an iterator of bits into a number. The bits should be in descending order (most- to least-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

impl BitConvertible for u32

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, it ends with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, it begins with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> u32

Converts an iterator of bits into a number. The bits should be in ascending order (least- to most-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> u32

Converts an iterator of bits into a number. The bits should be in descending order (most- to least-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

impl BitConvertible for u64

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, it ends with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, it begins with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> u64

Converts an iterator of bits into a number. The bits should be in ascending order (least- to most-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> u64

Converts an iterator of bits into a number. The bits should be in descending order (most- to least-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

impl BitConvertible for u128

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, it ends with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, it begins with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> u128

Converts an iterator of bits into a number. The bits should be in ascending order (least- to most-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> u128

Converts an iterator of bits into a number. The bits should be in descending order (most- to least-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

impl BitConvertible for usize

source§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in ascending order: least- to most-significant.

If the number is 0, the Vec is empty; otherwise, it ends with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the bits of a number in descending order: most- to least-significant.

If the number is 0, the Vec is empty; otherwise, it begins with true.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().

§Examples

See here.

source§

fn from_bits_asc<I: Iterator<Item = bool>>(bits: I) -> usize

Converts an iterator of bits into a number. The bits should be in ascending order (least- to most-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

source§

fn from_bits_desc<I: Iterator<Item = bool>>(bits: I) -> usize

Converts an iterator of bits into a number. The bits should be in descending order (most- to least-significant).

The function panics if the input represents a number that can’t fit in the output type.

$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is bits.count().

§Panics

Panics if the bits represent a value that isn’t representable by the output type.

§Examples

See here.

Implementors§