All pastes #1547592 Raw Edit

Count 1 Bits in Forth

public text v1 · immutable
#1547592 ·published 2009-08-29 20:45 UTC
rendered paste body
: (COUNTBITS) ( u1 u2 u3 -- u4 )
( count power mask -- count' )
ROT 2DUP AND >R ROT / AND R> +
;

: COUNTBITS ( u1 -- u2 )
( u2 = number of 1 bits in u1 )
2 21845 (COUNTBITS)
4 13107 (COUNTBITS)
16 1799 (COUNTBITS)
256 15 (COUNTBITS)
;