\ This program prints numbers in canonical signed digit (CSD) \ representation, a binary representation with the digits, 0, 1, and T \ (-1). This allows creating numbers with few non-zero digits and is \ useful for implementing multiplication by constants on machines \ without hardware multipliers. \ This programs was published by Rafael Deliano in Vierte Dimension \ 1/2007, and adapted for ANS Forth (with common extensions) by Anton \ Ertl. \ Usage: "u CSD." prints u in CSD representation. create SYM-TAB '0 C, '1 C, '1 C, '0 C, '0 C, 'T C, 'T C, '0 C, create Y+1-TAB 0 C, 0 C, 0 C, 1 C, 0 C, 1 C, 1 C, 1 C, : CSD. \ ( UN1 -- ) 1 lshift \ -- UN1' ) <# begin DUP 7 AND DUP SYM-TAB + C@ hold Y+1-TAB + C@ SWAP 1 rshift -2 AND OR dup 0= until dup #> type ;