Path: utzoo!attcan!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: F-PC Forth Tutorial Message-ID: <1056.UUL1.3#5129@willett.UUCP> Date: 1 Jun 90 03:45:51 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 71 Date: 05-30-90 (22:51) Number: 18 (Echo) To: JACK BROWN Refer#: NONE From: ROY RICE Read: NO Subj: LESSON3, CONT. Status: PUBLIC MESSAGE Jack: ex.3.7-9: \ rarl3b.seq continuation of answers to lesson 3, starting with ex.3.7 \ ex3.7 \ Illustration of Number bases and formatted display operators. \ modified by rar 05/28/90 20:02:05.74 : NTABLE ( dn -- ) CR ." unsigned" ." signed" ." unsigned" ." signed" ." unsigned" ." signed" CR ." decimal" ." decimal" ." octal " ." octal " ." hex " ." hex " 20 0 DO CR DECIMAL DUP 13 U.R DUP 13 .R OCTAL DUP 13 U.R DUP 13 .R HEX DUP 13 U.R DUP 13 .R 1+ LOOP DROP DECIMAL ; \ EX.3.8 : BINARY ( --) 2 BASE ! ; : .H ( n -- ) HEX . DECIMAL ; \ Display top number in HEX : U.HH ( n -- ) HEX U. DECIMAL ; \ Displlay top as unsigned HEX : .O ( n -- ) OCTAL . DECIMAL ; \ Display top number in OCTAL : U.O ( n -- ) OCTAL U. DECIMAL ; \ Display top as unsigned OCTAL : .B ( n -- ) BINARY . DECIMAL ; \ Display top number in BINARY : U.B ( n -- ) BINARY U. DECIMAL ; \ Display top as unsigned BINARY comment: The above definitions end with DECIMAL because we want to reset the base to decimal after outputting the number. They could be modified to save the current base and restore it after printing the number ( I think I saw this in Starting Forth) as in this definition to display the number in decimal and then restore the base: comment; : .D ( n -- ) BASE @ SWAP DECIMAL . BASE ! ; : U.D ( n -- ) BASE @ SWAP DECIMAL U. BASE ! ; : BNTABLE ( dn -- ) CR ." unsigned signed unsigned " ." signed unsigned signed" CR ." decimal decimal binary " ." binary hex hex" 20 0 DO CR DECIMAL DUP 10 U.R DUP 10 .R BINARY DUP 17 U.R DUP 17 .R HEX DUP 13 U.R DUP 13 .R 1+ LOOP DROP DECIMAL ; ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu