]> gitweb.factorcode.org Git - factor.git/blob - basis/math/bits/bits-docs.factor
Merge branch 'irc-fix' of git://tiodante.com/git/factor
[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 { $subsection bits }
11 { $subsection <bits> }
12 { $subsection make-bits } ;
13
14 HELP: bits
15 { $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 } "." } ;
16
17 HELP: <bits>
18 { $values { "number" integer } { "length" integer } { "bits" bits } }
19 { $description "Creates a virtual sequence of bits of a number in little endian order, with the given length." } ;
20
21 HELP: make-bits
22 { $values { "number" integer } { "bits" bits } }
23 { $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." }
24 { $examples
25     { $example "USING: math.bits prettyprint arrays ;" "BIN: 1101 make-bits >array ." "{ t f t t }" }
26     { $example "USING: math.bits prettyprint arrays ;" "-3 make-bits >array ." "{ t f }" }
27 } ;
28
29 HELP: unbits
30 { $values { "seq" sequence } { "number" integer } }
31 { $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." } ;