Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
program LogicGates;
var
Gate: string;
FBit, SBit: integer;
FBitBool, SBitBool: boolean;
begin
FBit:= 2;
SBit:= 2;
while ((Gate<>'and') and (Gate<>'or') and (Gate<>'xor') and (Gate<>'nand')) do
begin
writeln('Enter logic gate: ');
readln(Gate);
Gate := lowercase(Gate);
end;
while ((FBit<0) or (FBit>1)) do
begin
writeln('Enter first input: ');
readln(FBit);
end;
while ((SBit<0) or (SBit>1)) do
begin
writeln('Enter second input: ');
readln(SBit);
end;
if (FBit=1) then
FBitBool := true
else
FBitBool := false;
if (SBit=1) then
SBitBool := true
else
SBitBool := false;
if (Gate='and') then
begin
if (FBitBool and SBitBool) then
writeln('Result: 1')
else
writeln('Result: 0');
end;
if (Gate='or') then
begin
if (FBitBool or SBitBool) then
writeln('Result: 1')
else
writeln('Result: 0');
end;
if (Gate='xor') then
begin
if (FBitBool xor SBitBool) then
writeln('Result: 1')
else
writeln('Result: 0');
end;
if (Gate='nand') then
begin
if (FBitBool=false and SBitBool=false) then
writeln('Result: 1')
else
writeln('Result: 0');
end;
readln();
end.
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more