       ͻ
        Lesson 2 Part 025  F-PC 3.5 Tutorial by Jack Brown 
       ͼ

Ŀ
 Signed 16-bit integers:  


Range from -32768 through 32767
16-bit signed integers are often called single length signed numbers.

Examples.
  Binary             Hex      Decimal
0000000000000000    0000      0
0111111111111111    7FFF      32767
1000000000000000    8000      -32768
1111111111111111    FFFF      -1

Because 16 bit integers have such a small range you may get some
surprising results from some simple arithmetic operations.

Adding 1 to the largest positive number results in the largest negative
number.

32767 1 + . <enter> -32768 ok

What's happening here?
20000 20000 + . <enter> -25536  ok
20000 20000 * . <enter> -31744  ok

Luckily it is easy for Forth to deal with larger integer formats.
A common extension is to use double length signed integers or 32-bit
integers.  It is also possible to move to quadruple length or 64-bit
integers if the extra range is required.

For now we should be aware that it is fairly easy to exceed the range of
the 16-bit integers used on Forth's parameter stack.  We will be using
Forth's parameter stack for our first programming examples that involve
arithmetic.

Unsigned 16-bit integers.

Range: from 0 through 65,535.
16-bit unsigned integers are often called single length unsigned
numbers.

Examples.
  Binary             Hex      Decimal
0000000000000000    0000      0
0111111111111111    7FFF      32,767
1000000000000000    8000      32,768
1111111111111111    FFFF      65,535

What's happening here?  ( Note:  In U. the U stands for unsigned!)
32767 1 +     U. <enter> 32768  ok     <--- correct this time!
20000 20000 + U. <enter> 40000  ok     <--- correct this time!
20000 20000 * U. <enter> 33792  ok     <--- still wrong! why?

ķ
 Problem 2.1  
Ľ
Both + and - operators work fine for unsigned numbers.
Is this the case for * and / ?  If your answer is no then upload
you explanation as to why they don't work.

Ŀ
  Please move to Lesson 2 Part 030  

