Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: F-PC Forth Tutorial Message-ID: <928.UUL1.3#5129@willett.UUCP> Date: 9 May 90 03:44:55 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 103 Date: 05-06-90 (23:24) Number: 2 (Echo) To: JACK BROWN Refer#: NONE From: PAUL BRANNON Read: NO Subj: L. 3, P. 3 EXERCISES Status: PUBLIC MESSAGE Jack, Here are some more solutions to the exercises. (More to come) Paul \ exercise 3.7 single number display operator table : 1table ( n -- ) cr 1 spaces ." unsigned " ." signed " ." unsigned " ." signed " ." unsigned " ." signed " cr 1 spaces ." decimal " ." decimal " ." otcal " ." 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 cr ; \ output below is from word above -9 1table unsigned signed unsigned signed un91gned signed decimal decimal otcal octal hex hex 65527 -9 177767 -11 FFF7 -9 65528 -8 177770 -10 FFF8 -8 65529 -7 177771 -7 FFF9 -7 65530 -6 177772 -6 FFFA -6 65531 -5 177773 -5 FFFB -5 65532 -4 177774 -4 FFFC -4 65533 -3 177775 -3 FFFD -3 65534 -2 177776 -2 FFFE -2 65535 -1 177777 -1 FFFF -1 0 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 8 8 10 10 8 8 9 9 11 11 9 9 10 10 12 12 A A \ lesson 3, part 4, exercise 3.8 : binary ( -- ) 2 base ! ; : .h ( n -- ) hex . decimal ; : u.h ( n -- ) hex u. decimal ; : .o ( n -- ) octal . decimal ; : u.o ( n -- ) octal u. decimal ; : .b ( n -- ) binary . decimal ; : u.b ( n -- ) binary u. decimal ; : test_base_printing ( -- ) 16 -5 do cr i . i u. i .h i u.h i .o i u.o i .b i u.b loop cr ; The base value is reset to decimal after each word to make sure that sure that the stack is a familiar base, without suprises. Since each word resets the base value to decimal, there is not a need within these words, but if there are words for printing binary, octal, and hexadecimal values, there should be one for printing decimal values, since the current base cannot always be assumed to be decimal. test_base_printing -5 65531 -5 FFFB -5 177773 -101 1111111111111011 -4 65532 -4 FFFC -4 177774 -100 1111111111111100 -3 65533 -3 FFFD -3 177775 -11 1111111111111101 -2 65534 -2 FFFE -2 177776 -10 1111111111111110 -1 65535 -1 FFFF -1 177777 -1 1111111111111111 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 10 10 3 3 3 3 3 3 11 11 4 4 4 4 4 4 100 100 5 5 5 5 5 5 101 101 6 6 6 6 6 6 110 110 7 7 7 7 7 7 111 111 8 8 8 8 10 10 1000 1000 9 9 9 9 11 11 1001 1001 10 10 A A 12 12 1010 1010 11 11 B B 13 13 1011 1011 12 12 C C 14 14 1100 1100 13 13 D D 15 15 1101 1101 14 14 E E 16 16 1110 1110 15 15 F F 17 17 1111 1111 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'