2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,21 +1,21 @@
: >gray ( n -- n ) dup 2/ xor ;
: >gray ( n -- n' ) dup 2/ xor ; \ n' = n xor (n logically right shifted 1 time)
\ 2/ is Forth divide by 2, ie: shift right 1
: gray> ( n -- n )
0 1 31 lshift ( g b mask )
0 1 31 lshift ( -- g b mask )
begin
>r
>r \ save a copy of mask on return stack
2dup 2/ xor
r@ and or
r> 1 rshift
dup 0=
r> 1 rshift
dup 0=
until
drop nip ;
drop nip ; \ clean the parameter stack leaving result only
: test
2 base !
2 base ! \ set system number base to 2. ie: Binary
32 0 do
cr i dup 5 .r ." ==> "
cr I dup 5 .r ." ==> " \ print numbers (binary) right justified 5 places
>gray dup 5 .r ." ==> "
gray> 5 .r
loop
decimal ;
decimal ; \ revert to BASE 10