integer>bit-array ( n -- bit-array ) - Factor Documentation

integer>bit-array ( n -- bit-array )
Bit arrays



Vocabulary
bit-arrays

Inputs
n an integer


Outputs
bit-array a bit-array


Word description
Outputs a freshly-allocated bit array whose elements correspond to the bits in the binary representation of the given unsigned integer value.

Notes
The bits of the integer are stored in the resulting bit array in order of ascending significance, least significant bit first. This word will fail if passed a negative integer. If you want the two's-complement binary representation of a negative number, use bitnot to get the complement of the number first. This word works with fixnums or bignums of any size; it is not limited by fixnum size or machine word size.

Definition
USING: bit-arrays.private endian kernel math ;

IN: bit-arrays

: integer>bit-array ( n -- bit-array )
dup 0 =
[ <bit-array> ] [
dup log2 1 + [ nip ] [ bits>bytes >le ] 2bi
bit-array boa
] if ;

AltStyle によって変換されたページ (->オリジナル) /