help me explain this python code step boy step choice = True while choice==True:         n = int(input(" 1. Binary To decimal\n\ 2. Decimal to Hexadecimal\n\ 3. Binary to Hexadecimal\n\ 4. Decimal to Binary\n\ 5. Hexadecimal to Decimal\n\ 6. Hexadecimal to Binary\n\ 7. Addition of Binary numbers\n\ 8. Subtraction of Binary numbers\n\ 9. Multiplication of Binary numbers\n\ 10. Division of Binary numbers\n\ 11. exit program\n\ Enter your choice: ") the rest is on the images

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

help me explain this python code step boy step

choice = True
while choice==True:
        n = int(input("
1. Binary To decimal\n\
2. Decimal to Hexadecimal\n\
3. Binary to Hexadecimal\n\
4. Decimal to Binary\n\
5. Hexadecimal to Decimal\n\
6. Hexadecimal to Binary\n\
7. Addition of Binary numbers\n\
8. Subtraction of Binary numbers\n\
9. Multiplication of Binary numbers\n\
10. Division of Binary numbers\n\
11. exit program\n\
Enter your choice: ")
the rest is on the images



15
if n==1:
54
if b >= 32768:
55
b = b - 65536
# Code to convert binary to decimal
s = input("\nEnter Binary value: ")
print("Decimal value is: ",int(s,2))
16
sum = a + b
print("Decimal value of sum:
17
araa.
56
18
57
sum)
19
58
20
elif n==2:
59
elif n==8:
# Code to subtract two binary numbers
s = input("\nEnter first Binary value in 2's complement:
21
# Code to convert decimal to hexadecimal
60
S = input("\nEnter Decimal value: ")
print ("Hexadecimal value is: ", hex(int(s))[2:].upper())
22
61
a = int(s,2)
s = input("\nEnter second Binary value in 2's complement
b = int(s,2)
23
62
24
63
25
elif n==3:
64
if a >= 32768:
# Code to convert binary to hexadecimal
s = input("\nEnter Binary value: ")
print("Hexadecimal value is: ", hex(int(int(s,2)))[2:].u
26
65
27
66
a = a - 65536
28
67
if b >= 32768:
29
68
b = b - 65536
30
elif n==4:
69
diff = a - b
70
print ("Decimal value of difference: ", diff)
# Code to convert decimal to binary
s = int(input("\nEnter Decimal value: "))
print("Binary value is: ", bin(s).replace ("Ob", ""))
31
32
71
33
72
elif n==9:
# Code to Multiplication two binary numbers
s = input("\nEnter first Binary value in 2's complement:
a = int(s,2)
s = input("\nEnter second Binary value in 2's complement
b = int(s,2)
34
73
35
74
36
elif n==5:
75
37
# Code to convert hex to decimal
76
S = input("\nEnter Hexadecimal value: ")
print("Decimal value is: ", int(s, 16))
38
77
39
78
if a >= 32768:
40
79
a = a - 65536
41
elif n==6:
80
if b >= 32768:
81
b = b - 65536
# Code to convert hex to binary
s = input("\nEnter Hexadecimal value: ")
print("Binary value is: ", bin(int(s, 16))[2:].upper())
42
43
82
mul = a * b
44
83
print ("Decimal value of product: ".
mul)
45
84
46
elif n==7:
85
86
elif n==10:
# Code to add two binary numbers
s = input("\nEnter first Binary value in 2's complement:
a = int(s,2)
s = input("\nEnter second Binary value in 2's complement
b = int(s,2)
if a >= 32768:
47
# Code to Division two binary numbers
s = input("\nEnter first Binary value in 2's complement:
a = int(s,2)
s = input("\nEnter second Binary value in 2's complement
b = int(s,2)
48
87
49
88
50
89
51
90
52
91
53
a = a - 65536
92
if a >= 32768:
Transcribed Image Text:15 if n==1: 54 if b >= 32768: 55 b = b - 65536 # Code to convert binary to decimal s = input("\nEnter Binary value: ") print("Decimal value is: ",int(s,2)) 16 sum = a + b print("Decimal value of sum: 17 araa. 56 18 57 sum) 19 58 20 elif n==2: 59 elif n==8: # Code to subtract two binary numbers s = input("\nEnter first Binary value in 2's complement: 21 # Code to convert decimal to hexadecimal 60 S = input("\nEnter Decimal value: ") print ("Hexadecimal value is: ", hex(int(s))[2:].upper()) 22 61 a = int(s,2) s = input("\nEnter second Binary value in 2's complement b = int(s,2) 23 62 24 63 25 elif n==3: 64 if a >= 32768: # Code to convert binary to hexadecimal s = input("\nEnter Binary value: ") print("Hexadecimal value is: ", hex(int(int(s,2)))[2:].u 26 65 27 66 a = a - 65536 28 67 if b >= 32768: 29 68 b = b - 65536 30 elif n==4: 69 diff = a - b 70 print ("Decimal value of difference: ", diff) # Code to convert decimal to binary s = int(input("\nEnter Decimal value: ")) print("Binary value is: ", bin(s).replace ("Ob", "")) 31 32 71 33 72 elif n==9: # Code to Multiplication two binary numbers s = input("\nEnter first Binary value in 2's complement: a = int(s,2) s = input("\nEnter second Binary value in 2's complement b = int(s,2) 34 73 35 74 36 elif n==5: 75 37 # Code to convert hex to decimal 76 S = input("\nEnter Hexadecimal value: ") print("Decimal value is: ", int(s, 16)) 38 77 39 78 if a >= 32768: 40 79 a = a - 65536 41 elif n==6: 80 if b >= 32768: 81 b = b - 65536 # Code to convert hex to binary s = input("\nEnter Hexadecimal value: ") print("Binary value is: ", bin(int(s, 16))[2:].upper()) 42 43 82 mul = a * b 44 83 print ("Decimal value of product: ". mul) 45 84 46 elif n==7: 85 86 elif n==10: # Code to add two binary numbers s = input("\nEnter first Binary value in 2's complement: a = int(s,2) s = input("\nEnter second Binary value in 2's complement b = int(s,2) if a >= 32768: 47 # Code to Division two binary numbers s = input("\nEnter first Binary value in 2's complement: a = int(s,2) s = input("\nEnter second Binary value in 2's complement b = int(s,2) 48 87 49 88 50 89 51 90 52 91 53 a = a - 65536 92 if a >= 32768:
84
85
elif n==10:
# Code to Division two binary numbers
s = input("\nEnter first Binary value in 2's complement:
int(s,2)
s = input("\nEnter second Binary value in 2's complement
b = int(s,2)
if a >= 32768:
86
87
88
89
a
%3D
90
%3D
91
92
93
a - 65536
a
%3D
94
if b >= 32768:
95
b = b - 65536
a//b
onb
print("Decimal value of quotient: ", quo)
96
97
98
99
100
elif n==11:
101
break
102
103
else:
104
print("\nInvalid input")
105
106
Transcribed Image Text:84 85 elif n==10: # Code to Division two binary numbers s = input("\nEnter first Binary value in 2's complement: int(s,2) s = input("\nEnter second Binary value in 2's complement b = int(s,2) if a >= 32768: 86 87 88 89 a %3D 90 %3D 91 92 93 a - 65536 a %3D 94 if b >= 32768: 95 b = b - 65536 a//b onb print("Decimal value of quotient: ", quo) 96 97 98 99 100 elif n==11: 101 break 102 103 else: 104 print("\nInvalid input") 105 106
Expert Solution
steps

Step by step

Solved in 2 steps with 15 images

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