Chapter 3: Digital Elements and Features

Example3_1,pg 487

In [6]:
# equivalence comparator

import math
#Variable declaration
in1   = 1                 # input-1
in2   = not(in1)           # input-2


#Calculations
out=((not(in1))*( not(in2)))+(in1*in2)

#Result
print("output of comparator:")
print("out = %d"% out)
output of comparator:
out = 0

Example3_2,pg 487

In [8]:
# antivalence comparator

import math
#Variable declaration
in1   = 1                 # input-1
in2   = not(in1)          # input-2



#Calculations
out=((not(in1))+( not(in2)))*(in1+in2)

#Result
print("output of comparator:")
print("out = %d"%out)
output of comparator:
out = 1

Example3_3,pg 487

In [11]:
print("Theoretical example")
Theoretical example

Example3_4,pg 487

In [12]:
print("Theoretical example")
Theoretical example

Example3_5,pg 488

In [18]:
# simplify Boolean function

import math
#Variable declaration(Inputs)
#enter binary values only(1bit)
a=input("enter value of a")      #input-1
b=input("enter value of b")      #input-2
c=input("enter value of c")      #input-3
    
#Calculations
x=not(a and b)
y=(x or c)                       #final output

#Result
print("\noutput:y=%d\n"%y)
print("verify from truth table\n")
print("a  b  c          y\n")
print("0  0  0          1\n")
print("0  0  1          1\n")
print("0  1  0          1\n")
print("0  1  1          1\n")
print("1  0  0          1\n")
print("1  0  1          1\n")
print("1  1  0          0\n")
print("1  1  1          1\n")
enter value of a1
enter value of b1
enter value of c0

output:y=0

verify from truth table

a  b  c          y

0  0  0          1

0  0  1          1

0  1  0          1

0  1  1          1

1  0  0          1

1  0  1          1

1  1  0          0

1  1  1          1

Example3_6,pg 488

In [19]:
print("Theoretical example")
Theoretical example