Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Produce a flowchart for the following code :

import string
print('Binary Addition')
#getting inputs from user
x = input('x| enter 4 digits: ')
y = input('y| enter 4 digits: ')
#store the values of x and y in list and print the lists
list1 = list(x)
print(list1)

list2 = list(y)
print(list2)

#defining all the logic gates

# XOR gate
def xorgate(x,y):
if x == y:
return '0'
else:
return '1'
#AND gate
def andgate (x,y):
if x == '1' and y == '1':
return '1'
else:
return '0'
#ORgate
def orgate (x,y):
if x == '1' or y == '1':
return '1'
else:
return '0'

#define the circuit and provide all the list of inputs to the circuit.
#include the outputs depending on the gates function defined above.

def circuit(x,y,ci): #x and y are binary digits and ci is the output of the circuit
a = 3 #starting the value for while loop,to get appropriate position for our list
adder = ['0','0','0','0','0'] #adder list contains strings of zero.the list has to hold the binary numbers obtained by adding circuit
b = 4
#check a digit is >=0
while a >= 0:

#perform XOR,OR,AND in circuit here output of each operation is given to the next operation
xorout = xorgate(x[a],y[a])
print("xor:",(xorout))
s = xorgate(ci,xorout)
print("Ci:",ci)

andout = andgate(xorout, ci)
print("and1:",andout)
and2out = andgate(x[a],y[a])
print("and2:",and2out)

co = orgate(andout,and2out)
print('s:',s)
print('co:',co)
print('-----------------')

ci = co
adder[b] = str(s)
a-=1
b-=1


adder[0]=ci
#print Final Binary output
print('The Final Binary Output is:', adder)
adder = adder[::-1]
#Performing BINARY to decimal conversion
outputfinal = ((int(adder[4]) * 16) + (int(adder[3]) * 8)+(int(adder[2]) * 4)+(int(adder[1]) * 2)+(int(adder[0]) * 1))
print('The Final Decimal Output is:', outputfinal)
hold = '0'
circuit(list1,list2,hold)# 3 value for circuit

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY