5 ONERRORGOTO2000
10 CLS:MODE8:DIM:a=1:x=0:y=0:c$=CHR$(5):p=2^31:q=2^32:r=0:x$=" 0":ERASEa$,b$:DIMa$(5),b$(15)
40 RESTORE70
50 FORi=0 TO5:READa$(i):NEXT
60 FORi=0 TO15:READb$(i):NEXT
70 DATABIN,DEC,HEX,AND,OR,XOR
80 DATA0000,0001,0010,0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111
110 CLS:GOSUB300
120 z=LEN(x$):LOCATE0,0:IFz<17 THENPRINTc$;"[";a$(a);"] ";x$;ELSEPRINTc$;x$;
130 IFr>16 THENGOSUB300
140 r=z:LOCATE31,1
150 f=ASC(INPUT$(1)):IFf>96 THENf=f-32
160 IFf=73 THENGOSUB440:GOSUB290:GOTO330
170 IFf=66 ANDa<>0 THENa=0:GOTO330
180 IFf=68 ANDa<>1 THENa=1:GOTO330
190 IFf=72 ANDa<>2 THENa=2:GOTO330
200 IFf=42 ORf=43 ORf=45 ORf=47 THENGOSUB460:GOSUB290:GOTO800
210 IFf=65 ORf=79 ORf=88 THENGOSUB480:GOSUB290:GOTO900
220 IFf=76 ORf=82 THENGOSUB290:GOTO1040
230 IFf=78 ORf=67 THENGOSUB290:GOTO1100
240 IFf=46 THEN1200
250 GOTO150
270 LOCATE0,0:PRINTc$;"not found";:z$=INPUT$(1,@):RETURN
290 LOCATE0,0:PRINTc$;
300 LOCATE0,1:PRINT">I,B,D,H,+,-,*,/,A,O,X,N,C,L,R?";:RETURN
330 ONa+1 GOSUB360,350,360:GOTO120
350 x$=STR$(x):RETURN
360 IFx<0 THENt=x+q ELSEt=x
370 s=INT(t/65536):t=t-s*65536:x$=HEX$(s)+HEX$(t):IFa=2THENRETURN
380 y$="":FORi=1 TO8:y$=y$+b$(VAL("&H"+MID$(x$,i,1))):NEXT:x$=y$:RETURN
440 m$="Input data x (,B,D,H) ["+a$(a)+"] x ?":GOSUB550:x=y:RETURN
460 IFa>0 THENm$="["+a$(a)+"] " ELSEm$=""
465 m$=m$+x$+" "+CHR$(f)+" ":GOSUB550:RETURN
480 IFa>0 THENm$="["+a$(a)+"] " ELSEm$=""
485 m$=m$+x$+" "+a$(SGN(f-79)+4)+" ":GOSUB550:RETURN
550 CLS:PRINTm$;:INPUT@34;z$:LOCATE0,0:IFz$="" THENy=x:RETURN
560 l=LEN(z$):IFl>34 THENz$=LEFT$(z$,34)
570 d=a:c=l:IFl<2 THEN630
580 a$=MID$(z$,l-1,1)
590 IFa$="," ORa$="/" THENc=l-2:d=ASC(RIGHT$(z$,1)):z$=LEFT$(z$,c) ELSE630
600 IFd>96 THENd=d-32
610 IFd=66 ORd=68 ORd=72 THENd=SGN(d-68)+1 ELSE550
630 y=0:ONd+1 GOTO670,710,750
650 IFy<-p ORy>q-1 THEN550 ELSEIFy>=p THENy=y-q
660 RETURN
670 FORi=1TOc:z=ASC(MID$(z$,i,1))-48:IFz=0ORz=1THENy=y*2+z ELSE550
680 NEXT:GOTO650
710 e=0:w=0:FORi=1TOc:z=ASC(MID$(z$,i,1))
720 IF(z>47 ANDz<58) ORz=45 ORz=43 ORz=69 THEN730 ELSE550
730 IFw=0 THENy=INT(VALF(z$)):w=1:IFe=1 THEN550
740 NEXT:GOTO650
750 FORi=1 TOc:z=ASC(MID$(z$,i,1)):IFz>96 THENz=z-32
760 z=z-48:IFz<0 ORz>9 THENz=z-7:IFz<10 ORz>15 THEN550
770 y=y*16+z:NEXT:GOTO650
800 ONf-41 GOSUB840,850,,860,,870
810 IFw>=p ORw<-p THENGOSUB270:GOTO120 ELSEx=w:GOTO330
840 w=x*y:RETURN
850 w=x+y:RETURN
860 w=x-y:RETURN
870 w=FIX(x/y):RETURN
900 IFx<0 THENx=x+q
910 IFy<0 THENy=y+q
920 u=x-INT(x/65536)*65536:v=y-INT(y/65536)*65536:GOSUB950:z=u
930 u=INT(x/65536):v=INT(y/65536):GOSUB950:x=z+u*65536:IFx>=p THENx=x-q
940 GOTO330
950 IFu>32767 THENu=u-65536
960 IFv>32767 THENv=v-65536
970 IFf=65 THENu=u ANDv ELSEIFf=79 THENu=u ORv ELSEu=u XORv
980 IFu<0 THENu=u+65536
990 RETURN
1040 IFx<0 THENx=x+q
1050 IFf=76 THENx=x*2 ELSEx=INT(x/2)
1060 IFx>=q THENx=x-q
1070 IFx>=p THENx=x-q
1080 GOTO330
1100 IFf=78 THENx=-x-1 ELSEIFx>-p THENx=-x
1110 GOTO330
1200 CLS:GOSUB1300:i=2
1210 PRINT:ONi GOSUB1300,1310,1320,1330,1340,1350,1360,1370,1380,1390,1400,1410,1420,1430,1440
1220 z=ASC(INPUT$(1,@)):IFz=28 ORz=29 THEN110
1230 IFz<>13 ANDz<>30 ANDz<>31 THEN1220
1240 IF(z=30 ANDi=1) OR(z=31 ANDi=15) THEN1220
1250 IFz=30 THENi=i-2
1270 i=i+1:IFi<16 THEN1210
1280 GOTO110
1300 PRINT" I : input data";:RETURN
1310 PRINT" B : binary mode";:RETURN
1320 PRINT" D : decimal mode";:RETURN
1330 PRINT" H : hexadecimal mode";:RETURN
1340 PRINT" + : addition";:RETURN
1350 PRINT" - : subtraction";:RETURN
1360 PRINT" * : multiplication";:RETURN
1370 PRINT" / : division";:RETURN
1380 PRINT" A : AND";:RETURN
1390 PRINT" O : OR";:RETURN
1400 PRINT" X : XOR";:RETURN
1410 PRINT" N : NOT";:RETURN
1420 PRINT" C : 2's complement";:RETURN
1430 PRINT" L : bit shift left";:RETURN
1440 PRINT" R : bit shift right";:RETURN
2000 IFERR=1 THENCLS:ONERRORGOTO0
2010 IFERL>=840 ANDERR=<870 THENGOSUB270:RESUME120
2020 IFERL=730 THENe=1:RESUMENEXT
2030 GOSUB270:RESUME110