HP 3000 Manuals

Bit16 [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

Bit16 

The predefined data type bit16 is a subrange, 0..65535, that is stored in
16 bits.  bit16 is a unique HP Pascal type because arithmetic operations
on bit16 data are truncated to modulo 65535 when stored.

To determine if a type T is assignment compatible with bit16, treat bit16 
as a subrange of integer:

   *   If variable v is of type T and variable b16 is of type bit16, then
       the assignment b16 := v is legal if the value of v is within the
       range 0..65535.

   *   If the ranges of T and bit16 do not overlap, the assignment b16 :=
       v causes a compile-time error.

   *   If the ranges of T and bit16 do overlap, but the value of v is
       outside the range of bit16, then the assignment b16 := v causes a
       run-time error.

Example 

     PROGRAM prog;

     TYPE
        T1 = integer;     {overlaps bit16 range        }
        T2 = -32768..-1;  {does not overlap bit16 range}
        T3 = 0..65535;    {overlaps bit16 range        }

     VAR
        v1 : T1;  {b16:=v1 may be legal, depending on value of v1}
        v2 : T2;  {b16:=v2 is never legal}
        v3 : T3;  {b16:=v3 is always legal}
       b16 : bit16;

     BEGIN {prog}
        v1  := 65535;
        b16 := v1;       {legal}
        b16 := b16 + 5;  {legal; now b16 = (65540 MOD 65535) = 4}
        b16 := b16 - 5;  {legal; now b16 = 65535}

        v3 := 65535;
        v3 := v3 + 4;    {causes run-time error}
        v3 := 4;
        v3 := v3 - 5;    {causes run-time error}

        v1  := -20;
        b16 := v1;       {causes run-time error}

        v2  := -30;
        b16 := v2;       {causes compile-time error}
     END. {prog}



MPE/iX 5.0 Documentation