pub trait BitConvertible {
    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

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

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

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

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

Implementations on Foreign Types

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Implementors