{--------------------------------------------------------------}
{                           BINARY                             }
{                                                              }
{                Bit test demonstration program                }
{                                                              }
{                             by Jeff Duntemann                }
{                             Turbo Pascal V3.0                }
{                             Last update 1/31/86              }
{                                                              }
{    From the book, COMPLETE TURBO PASCAL, by Jeff Duntemann   }
{    Scott, Foresman & Co. (c) 1986,1987  ISBN 0-673-18600-8   }
{--------------------------------------------------------------}

PROGRAM BinaryDemo;

VAR 
  I,J : Integer;


FUNCTION TestBit(VAR Target; BitNum : Integer) : Boolean;

VAR 
  Subject : Integer ABSOLUTE Target;
  Dummy   : Integer;

BEGIN
  Dummy := Subject;
  Dummy := Dummy SHR BitNum;
  IF Odd(Dummy) THEN TestBit := True
    ELSE TestBit := False
END;


BEGIN
  REPEAT
    Write('>>Enter an integer (0 to exit): ');
    Readln(I);
    FOR J := 15 DOWNTO 0 DO
      IF TestBit(I,J) THEN Write('1') ELSE Write('0');
    Writeln; Writeln
  UNTIL I = 0
END.
