]> gitweb.factorcode.org Git - factor.git/blob - basis/math/bits/bits-docs.factor
use radix literals
[factor.git] / basis / math / bits / bits-docs.factor
1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.syntax help.markup math sequences ;
4 IN: math.bits
5
6 ABOUT: "math.bits"
7
8 ARTICLE: "math.bits" "Number bits virtual sequence"
9 "The " { $vocab-link "math.bits" } " vocabulary implements a virtual sequence which presents an integer as a sequence of bits, with the first element of the sequence being the least significant bit of the integer."
10 { $subsections
11     bits
12     <bits>
13     make-bits
14 } ;
15
16 HELP: bits
17 { $class-description "Virtual sequence class of bits of a number. The first bit is the least significant bit. This can be constructed with " { $link <bits> } " or " { $link make-bits } "." } ;
18
19 HELP: <bits>
20 { $values { "number" integer } { "length" integer } { "bits" bits } }
21 { $description "Creates a virtual sequence of bits of a number in little endian order, with the given length." } ;
22
23 HELP: make-bits
24 { $values { "number" integer } { "bits" bits } }
25 { $description "Creates a " { $link bits } " object out of the given number, using its log base 2 as the length. This implies that the last element, corresponding to the most significant bit, will be 1." }
26 { $examples
27     { $example "USING: math.bits prettyprint arrays ;" "0b1101 make-bits >array ." "{ t f t t }" }
28     { $example "USING: math.bits prettyprint arrays ;" "-3 make-bits >array ." "{ t f }" }
29 } ;
30
31 HELP: unbits
32 { $values { "seq" sequence } { "number" integer } }
33 { $description "Turns a sequence of booleans, of the same format made by the " { $link bits } " class, and calculates the number that it represents as little-endian." } ;