home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l2p025 < prev    next >
Text File  |  1990-07-15  |  2KB  |  69 lines

  1.        ╔════════════════════════════════════════════════════╗
  2.        ║ Lesson 2 Part 025  F-PC 3.5 Tutorial by Jack Brown ║
  3.        ╚════════════════════════════════════════════════════╝
  4.  
  5. ┌──────────────────────────┐
  6. │ Signed 16-bit integers:  │
  7. └──────────────────────────┘
  8.  
  9. Range from -32768 through 32767
  10. 16-bit signed integers are often called single length signed numbers.
  11.  
  12. Examples.
  13.   Binary             Hex      Decimal
  14. 0000000000000000    0000      0
  15. 0111111111111111    7FFF      32767
  16. 1000000000000000    8000      -32768
  17. 1111111111111111    FFFF      -1
  18.  
  19. Because 16 bit integers have such a small range you may get some
  20. surprising results from some simple arithmetic operations.
  21.  
  22. Adding 1 to the largest positive number results in the largest negative
  23. number.
  24.  
  25. 32767 1 + . <enter> -32768 ok
  26.  
  27. What's happening here?
  28. 20000 20000 + . <enter> -25536  ok
  29. 20000 20000 * . <enter> -31744  ok
  30.  
  31. Luckily it is easy for Forth to deal with larger integer formats.
  32. A common extension is to use double length signed integers or 32-bit
  33. integers.  It is also possible to move to quadruple length or 64-bit
  34. integers if the extra range is required.
  35.  
  36. For now we should be aware that it is fairly easy to exceed the range of
  37. the 16-bit integers used on Forth's parameter stack.  We will be using
  38. Forth's parameter stack for our first programming examples that involve
  39. arithmetic.
  40.  
  41. Unsigned 16-bit integers.
  42.  
  43. Range: from 0 through 65,535.
  44. 16-bit unsigned integers are often called single length unsigned
  45. numbers.
  46.  
  47. Examples.
  48.   Binary             Hex      Decimal
  49. 0000000000000000    0000      0
  50. 0111111111111111    7FFF      32,767
  51. 1000000000000000    8000      32,768
  52. 1111111111111111    FFFF      65,535
  53.  
  54. What's happening here?  ( Note:  In U. the U stands for unsigned!)
  55. 32767 1 +     U. <enter> 32768  ok     <--- correct this time!
  56. 20000 20000 + U. <enter> 40000  ok     <--- correct this time!
  57. 20000 20000 * U. <enter> 33792  ok     <--- still wrong! why?
  58.  
  59. ╓──────────────╖
  60. ║ Problem 2.1  ║
  61. ╙──────────────╜
  62. Both + and - operators work fine for unsigned numbers.
  63. Is this the case for * and / ?  If your answer is no then upload
  64. you explanation as to why they don't work.
  65.  
  66. ┌────────────────────────────────────┐
  67. │  Please move to Lesson 2 Part 030  │
  68. └────────────────────────────────────┘
  69.