DEFINITION BIT; (* portable *)

 TYPE
  SHORTCARD = SHORTINT;
  CARDINAL = INTEGER;
  LONGCARD = LONGINT;

 (* bitwise exclusive or: x XOR y *)
 PROCEDURE CXOR (x, y: CHAR): CHAR;
 PROCEDURE SXOR (x, y: SHORTINT): SHORTINT;
 PROCEDURE IXOR (x, y: INTEGER): INTEGER;
 PROCEDURE LXOR (x, y: LONGINT): LONGINT;

 (* bitwise or: x OR y *)
 PROCEDURE COR (x, y: CHAR): CHAR;
 PROCEDURE SOR (x, y: SHORTINT): SHORTINT;
 PROCEDURE IOR (x, y: INTEGER): INTEGER;
 PROCEDURE LOR (x, y: LONGINT): LONGINT;

 (* bitwise and: x AND y *)
 PROCEDURE CAND (x, y: CHAR): CHAR;
 PROCEDURE SAND (x, y: SHORTINT): SHORTINT;
 PROCEDURE IAND (x, y: INTEGER): INTEGER;
 PROCEDURE LAND (x, y: LONGINT): LONGINT;

 (* bitwise logical left-shift: x shifted n *)
 PROCEDURE CLSH (x: CHAR; n: SHORTINT): CHAR;
 PROCEDURE SLSH (x: SHORTINT; n: SHORTINT): SHORTINT;
 PROCEDURE ILSH (x: INTEGER; n: SHORTINT): INTEGER;
 PROCEDURE LLSH (x: LONGINT; n: SHORTINT): LONGINT;

 (* bitwise rotation: x rotatated by n bits *)
 PROCEDURE CROT (x: CHAR; n: SHORTINT): CHAR;
 PROCEDURE SROT (x: SHORTINT; n: SHORTINT): SHORTINT;
 PROCEDURE IROT (x: INTEGER; n: SHORTINT): INTEGER;
 PROCEDURE LROT (x: LONGINT; n: SHORTINT): LONGINT;

 (* swap bytes to change byteordering *)
 PROCEDURE ISWAP (x: INTEGER): INTEGER;
 PROCEDURE LSWAP (x: LONGINT): LONGINT;

 (* test bit n in x*)
 PROCEDURE CBIT (x: CHAR; n: SHORTINT): BOOLEAN;
 PROCEDURE BIT (x: LONGINT; n: SHORTINT): BOOLEAN;

 (* set bit n in x*)
 PROCEDURE CSETBIT (VAR x: CHAR; n: SHORTINT);
 PROCEDURE SSETBIT (VAR x: SHORTINT; n: SHORTINT);
 PROCEDURE ISETBIT (VAR x: INTEGER; n: SHORTINT);
 PROCEDURE LSETBIT (VAR x: LONGINT; n: SHORTINT);

 (* clear bit n in x*)
 PROCEDURE CCLRBIT (VAR x: CHAR; n: SHORTINT);
 PROCEDURE SCLRBIT (VAR x: SHORTINT; n: SHORTINT);
 PROCEDURE ICLRBIT (VAR x: INTEGER; n: SHORTINT);
 PROCEDURE LCLRBIT (VAR x: LONGINT; n: SHORTINT);

 (* unsigned comparison: x < y *)
 PROCEDURE SLESS (x, y: SHORTCARD): BOOLEAN;
 PROCEDURE ILESS (x, y: CARDINAL): BOOLEAN;
 PROCEDURE LLESS (x, y: LONGCARD): BOOLEAN;

 (* unsigned comparison: x <= y *)
 PROCEDURE SLESSEQ (x, y: SHORTCARD): BOOLEAN;
 PROCEDURE ILESSEQ (x, y: CARDINAL): BOOLEAN;
 PROCEDURE LLESSEQ (x, y: LONGCARD): BOOLEAN;

 (* unsigned division: x DIV y *)
 PROCEDURE SDIV (x, y: SHORTCARD): SHORTCARD;
 PROCEDURE IDIV (x, y: CARDINAL): CARDINAL;
 PROCEDURE LDIV (x, y: LONGCARD): LONGCARD;

END BIT.