Boolean with logic operators ( and | or | xor | not )
Boolean with ( and | or | xor | not )
Pas2JS pascal source code
var
i, j: Integer;
BEGIN
{ BASIC LOGIC OPERATIONS }
for i:=0 to 1 do begin
for j:=0 to 1 do begin
WriteLn('>> i='+IntToStr(i)+', j='+IntToStr(j));
if (i=0) and (j=0) then WriteLn('=0 and');
if (i=0) or (j=0) then WriteLn('=0 or');
if (i=0) xor (j=0) then WriteLn('=0 xor');
if (i<>0) and (j<>0) then WriteLn('<>0 and');
if (i<>0) or (j<>0) then WriteLn('<>0 or');
if (i<>0) xor (j<>0) then WriteLn('<>0 xor');
if not((i=0) and (j=0)) then WriteLn('not =0 and');
if not((i=0) or (j=0)) then WriteLn('not =0 or');
if not((i=0) xor (j=0)) then WriteLn('not =0 xor');
if not((i<>0) and (j<>0)) then WriteLn('not <>0 and');
if not((i<>0) or (j<>0)) then WriteLn('not <>0 or');
if not((i<>0) xor (j<>0)) then WriteLn('not <>0 xor');
end;
end;
{ CONSOLE OUTPUTS
>> i=0, j=0
=0 and
=0 or
not =0 xor
not <>0 and
not <>0 or
not <>0 xor
>> i=0, j=1
=0 or
=0 xor
<>0 or
<>0 xor
not =0 and
not <>0 and
>> i=1, j=0
=0 or
=0 xor
<>0 or
<>0 xor
not =0 and
not <>0 and
>> i=1, j=1
<>0 and
<>0 or
not =0 and
not =0 or
not =0 xor
not <>0 xor
}
var i = 0;
var j = 0;
for(i=0;i<=1;i++) {
for(j=0;j<=1;j++) {
WriteLn((">> i="+i.toString()+", j="+j.toString()));
if ((i==0)&&(j==0)) {
WriteLn("=0 and");
}
if ((i==0)||(j==0)) {
WriteLn("=0 or");
}
if ((!(i==0) != !(j==0))) {
WriteLn("=0 xor");
}
if ((i!=0)&&(j!=0)) {
WriteLn("<>0 and");
}
if ((i!=0)||(j!=0)) {
WriteLn("<>0 or");
}
if ((!(i!=0) != !(j!=0))) {
WriteLn("<>0 xor");
}
if (!((i==0)&&(j==0))) {
WriteLn("not =0 and");
}
if (!((i==0)||(j==0))) {
WriteLn("not =0 or");
}
if (!(!(i==0) != !(j==0))) {
WriteLn("not =0 xor");
}
if (!((i!=0)&&(j!=0))) {
WriteLn("not <>0 and");
}
if (!((i!=0)||(j!=0))) {
WriteLn("not <>0 or");
}
if (!(!(i!=0) != !(j!=0))) {
WriteLn("not <>0 xor");
}
}
}