1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.functions quotations words sequences
4 sequences.private combinators fry ;
15 0 swap [ [ 1+ ] when ] each-bit
16 ] B{ } map-as '[ HEX: ff bitand , nth-unsafe ] define-inline
20 GENERIC: (bit-count) ( x -- n )
25 [ -8 shift byte-bit-count ]
26 [ -16 shift byte-bit-count ]
27 [ -24 shift byte-bit-count ]
32 [ byte-bit-count ] [ -8 shift (bit-count) ] bi +
37 : bit-count ( x -- n )
38 dup 0 >= [ (bit-count) ] [ bitnot (bit-count) ] if ; inline