      REM BLD.TBL
*PIC-LAN
*
*ALL
*PC
*N
*
*
*
*
******************************************************************************
******************************************************************************
***                                                                        ***
*** (C) Copyright 1990-2005 Doug Dumitru, All Rights Reserved.             ***
***                                                                        ***
*** This program is licensed under the terms of the GNU General Public     ***
*** License, version 2.0 with attached notices.                            ***
***                                                                        ***
*** The full text can be found in the LICENSE.TXT file in the              ***
*** PLIP.BP database file (the /usr/qmweb/PLIP.BP/PLIP.BP directory).      ***
***                                                                        ***
******************************************************************************
******************************************************************************
*
      INCLUDE SYS.TYPE.INCLUDE
*
      BIN.TBL = ''
      BIN.TBL<-1> = '0000'
      BIN.TBL<-1> = '0001'
      BIN.TBL<-1> = '0010'
      BIN.TBL<-1> = '0011'
      BIN.TBL<-1> = '0100'
      BIN.TBL<-1> = '0101'
      BIN.TBL<-1> = '0110'
      BIN.TBL<-1> = '0111'
      BIN.TBL<-1> = '1000'
      BIN.TBL<-1> = '1001'
      BIN.TBL<-1> = '1010'
      BIN.TBL<-1> = '1011'
      BIN.TBL<-1> = '1100'
      BIN.TBL<-1> = '1101'
      BIN.TBL<-1> = '1110'
      BIN.TBL<-1> = '1111'
*
      OPEN 'WWW.CTRL,TBL.MATH' TO TBL.FD ELSE CALL PLXX.STOP(201,'WWW.CTRL,TBL.MATH')
*
      CLEARFILE TBL.FD
*
      FOR D = 0 TO 15
         X = OCONV(D,'MCDX') 'R%1'
         GOSUB 1000
         WRITEV B ON TBL.FD , X , 1
         WRITEV X ON TBL.FD , B , 2
      NEXT D
*
      FOR D1 = 0 TO 15
         READ B1 FROM TBL.FD , OCONV(D1,'MCDX') ELSE STOP 'X'
         FOR D2 = 0 TO 15
            READ B2 FROM TBL.FD , OCONV(D2,'MCDX') ELSE STOP 'X'
            B.AND = ''
            B.OR  = ''
            B.XOR = ''
            FOR I = 1 TO 4
               IF B1[I,1] THEN
                  IF B2[I,1] THEN
                     B.AND = B.AND : '1'
                     B.OR  = B.OR  : '1'
                     B.XOR = B.XOR : '0'
                  END ELSE
                     B.AND = B.AND : '0'
                     B.OR  = B.OR  : '1'
                     B.XOR = B.XOR : '1'
                  END
               END ELSE
                  IF B2[I,1] THEN
                     B.AND = B.AND : '0'
                     B.OR  = B.OR  : '1'
                     B.XOR = B.XOR : '1'
                  END ELSE
                     B.AND = B.AND : '0'
                     B.OR  = B.OR  : '0'
                     B.XOR = B.XOR : '0'
                  END
               END
            NEXT I
*
            D = ''
            READV X FROM TBL.FD , B.AND , 2 ELSE STOP 'X'
            D<3> = X
            READV X FROM TBL.FD , B.OR , 2 ELSE STOP 'X'
            D<4> = X
            READV X FROM TBL.FD , B.XOR , 2 ELSE STOP 'X'
            D<5> = X
            WRITE D ON TBL.FD , OCONV(D1,'MCDX') : OCONV(D2,'MCDX')
*
         NEXT D2
         PRINT D1 : CR :
      NEXT D1
*
      STOP
*
1000  REM Convert X to B
*
      B = ''
      FOR I = 1 TO LEN(X)
         B = B : BIN.TBL<OCONV(X[I,1],'MCXD')+1>
      NEXT I
*
      RETURN
   END
