home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / basic / egbas.lbr / NUMREP.BZS / NUMREP.BAS
Encoding:
BASIC Source File  |  1988-01-24  |  1.9 KB  |  71 lines

  1. 0 REM 10-25-84 <-- last backup
  2. 10 PRINT CHR$(26)
  3. 20 PRINT"Eric Gans"
  4. 30 PRINT"French Department UCLA
  5. 40 PRINT"Los Angeles, CA 90024"
  6. 50 PRINT
  7. 60 REM deciphers BASIC number representation
  8. 70 PRINT TAB(30)"NUMREP":PRINT
  9. 80 PRINT"This program displays MBasic's representation of numbers in integer,"
  10. 90 PRINT"single or double precision.  The memory bytes are displayed in binary;"
  11. 100 PRINT"the decimal number displayed below is calculated from the memory, and"
  12. 110 PRINT"should be (approximately) identical to the first.":PRINT
  13. 120 PRINT"Integer,Single or Double, Q to quit (i/s/d/q)?"
  14. 130 E$=INPUT$(1)
  15. 140 IF E$="q" THEN END
  16. 150 IF E$="s" THEN 280 ELSE IF E$="d" THEN 420 ELSE IF E$<>"i" THEN 130
  17. 160 REM integer
  18. 170 DEFINT A
  19. 180 INPUT "Enter an integer (<CR> quits) >>",A
  20. 190 IF A=0 GOTO 120
  21. 200 FOR I=1 TO 2
  22. 210 N(I)=PEEK(VARPTR(A)+I-1)
  23. 220 N=N(I):GOSUB 590
  24. 230 NEXT
  25. 240 PRINT
  26. 250 NB=N(1)+((N(2) AND 127)-(N(2) AND 128))*2^8
  27. 260 PRINT NB
  28. 270 GOTO 180
  29. 280 REM single precision
  30. 290 DEFSNG A
  31. 300 INPUT "Enter a number (<CR> quits) >>",A
  32. 310 IF A=0 GOTO 120
  33. 320 FOR I=1 TO 4
  34. 330 N(I)=PEEK(VARPTR(A)+I-1)
  35. 340 N=N(I):GOSUB 590
  36. 350 NEXT
  37. 360 PRINT
  38. 370 EX=N(4)-129
  39. 380 NB=2^EX*(1+2^(-7)*(N(3) AND 127)+2^(-15)*N(2)+2^(-31)*N(1))
  40. 390 IF (N(3) AND 128) THEN NB=-NB
  41. 400 PRINT NB
  42. 410 GOTO 300
  43. 420 REM double precision
  44. 430 DEFDBL A,D
  45. 440 INPUT "Enter a number (<CR> quits) >>",A
  46. 450 IF A=0 GOTO 120
  47. 460 FOR I=1 TO 8
  48. 470 N(I)=PEEK(VARPTR(A)+I-1)
  49. 480 N=N(I):GOSUB 590
  50. 490 NEXT
  51. 500 PRINT
  52. 510 EX=N(8)-129
  53. 520 DNB=2^EX*(1+(N(7) AND 127)*2^(-7))
  54. 530 FOR I=6 TO 1 STEP-1
  55. 540 DNB=DNB+N(I)*(2^(EX-(8*(8-I)-1)))
  56. 550 NEXT
  57. 560 IF (N(7) AND 128) THEN DNB=-DNB
  58. 570 PRINT DNB
  59. 580 GOTO 440
  60. 590 REM binary
  61. 600 B=128
  62. 610 WHILE B>=1
  63. 620 IF (N AND B) THEN PRINT"1"; ELSE PRINT"0";
  64. 630 B=B/2
  65. 640 WEND
  66. 650 PRINT" ";
  67. 660 RETURN
  68. ry
  69. 600 B=128
  70. 610 WHILE B>=1
  71. 620 IF (N AND B) THEN PRINT"1