Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an additional function to perform a bitwise left shift or a bitwise right shift using the bitwise operators < < and > > .

Write an additional function to perform a bitwise left shift or a bitwise right shift using the bitwise operators << and >>.
Check that performing aleft shift by n place(s)is equivalent tomultiplying a number by 2n.
For instance 5<<3 is the same as 5\times 23=40.
Check that performing aright shift by n place(s)is equivalent todividing a number by 2n(whole division).
For instance 40>>3 is the same as 40/23=5.
#Truth Table Generator - www.101computing.net/truth-table-generator/
def truthTable(expression,inputs=2):
print("Boolean Expression:")
print(" X ="+ expression.upper())
expression = expression.lower()
#replace Boolean Operators with bitwise operators
expression = expression.replace("and","&")
expression = expression.replace("xor","^")
expression = expression.replace("or","|")
expression = expression.replace("not","~")
print("
Truth Table:")
if inputs==2:
print("-------------")
print("| A | B | X |")
print("-------------")
for a in range(0,2):
for b in range(0,2):
x = eval(expression)
print("|"+ str(a)+"|"+ str(b)+"|"+ str(x)+"|")
print("-------------")
elif inputs==3:
print("-----------------")
print("| A | B | C | X |")
print("-----------------")
for a in range(0,2):
for b in range(0,2):
for c in range(0,2):
x = eval(expression)
print("|"+ str(a)+"|"+ str(b)+"|"+ str(c)+"|"+ str(x)+"|")
print("-----------------")
elif inputs==4:
print("---------------------")
print("| A | B | C | D | X |")
print("---------------------")
for a in range(0,2):
for b in range(0,2):
for c in range(0,2):
for d in range(0,2):
x = eval(expression)
print("|"+ str(a)+"|"+ str(b)+"|"+ str(c)+"|"+ str(d)+"|"+ str(x)+"|")
print("---------------------")
##############################################
expression = "A AND NOT (B XOR C)"
truthTable(expression,3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions