0% found this document useful (0 votes)
2 views5 pages

Python Exp12

The document outlines Python programs for implementing digital logic gates: AND, OR, NOT, and EX-OR, as well as Half Adder and Full Adder. It includes code snippets for each gate and adder, along with their outputs. The result indicates a successful implementation and understanding of these digital logic concepts.

Uploaded by

adityanihal2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Python Exp12

The document outlines Python programs for implementing digital logic gates: AND, OR, NOT, and EX-OR, as well as Half Adder and Full Adder. It includes code snippets for each gate and adder, along with their outputs. The result indicates a successful implementation and understanding of these digital logic concepts.

Uploaded by

adityanihal2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EXPERIMENT-12

AIM: a) Write Python programs to implement Digital Logic Gates–AND, OR, NOT, EX-OR.
SOFTWARE USED: Python 3.6.0
AND Gate:
CODE:
def AND(a, b):
if a==1 and b==1:
return 1
else:
return 0
print("A B A AND B ")
print("0 0\t", AND(0,0))
print("0 1\t", AND(0,1))
print("1 0\t", AND(1,0))
print("1 1\t", AND(1,1))
OUTPUT:

OR Gate:
CODE:
def OR(a, b):
if a==0 and b==0:
return 0
else:
return 1
print("A B A OR B ")
print("0 0\t", OR(0,0))
print("0 1\t", OR(0,1))
print("1 0\t", OR(1,0))
print("1 1\t", OR(1,1))

OUTPUT:

NOT Gate:
CODE:
def NOT(a):
if(a==0):
return 1
elif(a==1):
return 0
print("A NOT(A) ")
print("0 \t", NOT(0))
print("1 \t", NOT(1))
OUTPUT:

EX-OR Gate:
CODE:
def XOR(a, b):
if a!=b:
return 1
else:
return 0
print("A B A XOR B ")
print("0 0\t", XOR(0,0))
print("0 1\t", XOR(0,1))
print("1 0\t", XOR(1,0))
print("1 1\t", XOR(1,1))
OUTPUT:

b) Write Python programs to implement Half Adder and Full Adder.


HALF ADDER:
CODE:
def AND(a, b):
if a==1 and b==1:
return 1
else:
return 0
def XOR(a, b):
if a!=b:
return 1
else:
return 0
def half_adder(a, b):
sum=XOR(a, b)
carry=AND(a, b)
return sum, carry

sum1,carry1=half_adder(0,0)
sum2,carry2=half_adder(0,1)
sum3,carry3=half_adder(1,0)
sum4,carry4=half_adder(1,1)
sum4,carry4=half_adder(1,1)
print("A B SUM CARRY ")
print("0 0\t", sum1,'\t',carry1)
print("0 1\t", sum2,'\t',carry2)
print("1 0\t", sum3,'\t',carry3)
print("1 1\t", sum4,'\t',carry4)
OUTPUT:

FULL ADDER:
CODE:
def AND(a, b):
if a==1 and b==1:
return 1
else:
return 0
def XOR(a, b):
if a!=b:
return 1
else:
return 0
def half_adder(a, b):
sum=XOR(a, b)
carry=AND(a, b)
return sum, carry
def full_adder(carry_in,a,b):
sum1,carry1=half_adder(carry_in,a)
sum2,carry2=half_adder(sum1,b)
carry=carry1 or carry2
return sum2,carry

s1,c1=full_adder(0,0,0)
s2,c2=full_adder(0,0,1)
s3,c3=full_adder(0,1,0)
s4,c4=full_adder(0,1,1)
s5,c5=full_adder(1,0,0)
s6,c6=full_adder(1,0,1)
s7,c7=full_adder(1,1,0)
s8,c8=full_adder(1,1,1)
print('\n')
print("A B C SUM CARRY ")
print("0 0 0\t", s1,'\t',c1)
print("0 0 1\t", s2,'\t',c2)
print("0 1 0\t", s3,'\t',c3)
print("0 1 1\t", s4,'\t',c4)
print("1 0 0\t", s5,'\t',c5)
print("1 0 1\t", s6,'\t',c6)
print("1 1 0\t", s7,'\t',c7)
print("1 1 1\t", s8,'\t',c8)
OUTPUT:

RESULT:
Implemented the python programs for Digital Logic Gates AND, OR, NOT, EX-OR and also Half Adder, Full
Adder, and Parallel Adder and understood the concepts.

You might also like