aboutsummaryrefslogtreecommitdiff
path: root/board-js2x/slof/helper.fs
diff options
context:
space:
mode:
Diffstat (limited to 'board-js2x/slof/helper.fs')
-rw-r--r--board-js2x/slof/helper.fs9
1 files changed, 9 insertions, 0 deletions
diff --git a/board-js2x/slof/helper.fs b/board-js2x/slof/helper.fs
index 1e2b030..c522c90 100644
--- a/board-js2x/slof/helper.fs
+++ b/board-js2x/slof/helper.fs
@@ -37,3 +37,12 @@
ENDCASE
drop
;
+
+\ count the number of bits equal 1
+\ the idea is to clear in each step the least significant bit
+\ v&(v-1) does exactly this, so count the steps until v == 0
+: cnt-bits ( 64-bit-value -- #bits=1 )
+ dup IF
+ 41 1 DO dup 1- and dup 0= IF drop i LEAVE THEN LOOP
+ THEN
+;