unbits word in math.bits vocab
parent
29395bf900
commit
52017e22f3
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2009 Daniel Ehrenberg
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: help.syntax help.markup math ;
|
||||
USING: help.syntax help.markup math sequences ;
|
||||
IN: math.bits
|
||||
|
||||
ABOUT: "math.bits"
|
||||
|
@ -24,3 +24,7 @@ HELP: make-bits
|
|||
{ $example "USING: math.bits prettyprint arrays ;" "BIN: 1101 make-bits >array ." "{ t f t t }" }
|
||||
{ $example "USING: math.bits prettyprint arrays ;" "-3 make-bits >array ." "{ t f }" }
|
||||
} ;
|
||||
|
||||
HELP: unbits
|
||||
{ $values { "seq" sequence } { "number" integer } }
|
||||
{ $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." } ;
|
||||
|
|
|
@ -29,3 +29,6 @@ IN: math.bits.tests
|
|||
[ t ] [
|
||||
1067811677921310779 >bignum make-bits last
|
||||
] unit-test
|
||||
|
||||
[ 6 ] [ 6 make-bits unbits ] unit-test
|
||||
[ 6 ] [ 6 3 <bits> >array unbits ] unit-test
|
||||
|
|
|
@ -14,3 +14,6 @@ M: bits length length>> ;
|
|||
M: bits nth-unsafe number>> swap bit? ;
|
||||
|
||||
INSTANCE: bits immutable-sequence
|
||||
|
||||
: unbits ( seq -- number )
|
||||
<reversed> 0 [ [ 1 shift ] dip [ 1+ ] when ] reduce ;
|
||||
|
|
Loading…
Reference in New Issue