
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
help me add this in my python code
- addition, subtraction, multiplication, division of binary numbers
-must be able to use two complement (negative numbers). Only integers, no fractions needed.
-Input & output 16 bit numbers
here's my on the images
and here's the n part :
n = int(input("1. Binary To decimal\n2. Decimal to Hexadecimal\n3. Binary to Hexadecimal\n4. Decimal to Binary\n5. Hexadecimal to Decimal\n6. Hexadecimal to Binary\nEnter your choice: "))
![choice = "yes"
while choice=="yes":
n = int(input("1. Binary To decimal\n2. Decimal to Hexadecimal\n3. Binary to Hexadecimal\n4. Decimal to Binary\n5. Hexadecimal to Decima
if n==1:
2
# Code to convert binary to decimal
s = input("\nEnter Binary value: ")
print ("Decimal value is: ",int(s,2))
5
6
7
8
9
elif n==2:
10
# Code to convert decimal to hexadecimal
s = input("\nEnter Decimal value: ")
print("Hexadecimal value is: ", hex(int(s))[2:].upper())
11
12
13
14
elif n==3:
# Code to convert binary to hexadecimal
s = input("\nEnter Binary value: ")
print("Hexadecimal value is: ", hex(int(int(s,2)))[2:].upper())
15
16
17
18
19
elif n==4:
# Code to convert decimal to binary
s = int(input("\nEnter Decimal value: "))
print("Binary value is: ", bin(s).replace("Ob", ""))
20
21
22
23
24
25
elif n==5:
26
# Code to convert hex to decimal
s = input("\nEnter Hexadecimal value: ")
print ("Decimal value is: ", int(s, 16))
27
28
29
30
elif n==6:
# Code to convert hex to binary
s = input("\nEnter Hexadecimal value: ")
print("Binary value is: ", bin(int(s, 16))[2:].upper())
31
32
33
34
35
else:
36
print ("\nInvalid input")
37
print("\nDo you want to do more: ")
choice=input("Enter you choice: ")
38
39](https://content.bartleby.com/qna-images/question/6fd5cc9b-0f4a-4f78-a8ef-859031ebfbed/6ad240ca-63fb-47ba-aeea-f4c7ea7f426c/kzx15f2_thumbnail.png)
Transcribed Image Text:choice = "yes"
while choice=="yes":
n = int(input("1. Binary To decimal\n2. Decimal to Hexadecimal\n3. Binary to Hexadecimal\n4. Decimal to Binary\n5. Hexadecimal to Decima
if n==1:
2
# Code to convert binary to decimal
s = input("\nEnter Binary value: ")
print ("Decimal value is: ",int(s,2))
5
6
7
8
9
elif n==2:
10
# Code to convert decimal to hexadecimal
s = input("\nEnter Decimal value: ")
print("Hexadecimal value is: ", hex(int(s))[2:].upper())
11
12
13
14
elif n==3:
# Code to convert binary to hexadecimal
s = input("\nEnter Binary value: ")
print("Hexadecimal value is: ", hex(int(int(s,2)))[2:].upper())
15
16
17
18
19
elif n==4:
# Code to convert decimal to binary
s = int(input("\nEnter Decimal value: "))
print("Binary value is: ", bin(s).replace("Ob", ""))
20
21
22
23
24
25
elif n==5:
26
# Code to convert hex to decimal
s = input("\nEnter Hexadecimal value: ")
print ("Decimal value is: ", int(s, 16))
27
28
29
30
elif n==6:
# Code to convert hex to binary
s = input("\nEnter Hexadecimal value: ")
print("Binary value is: ", bin(int(s, 16))[2:].upper())
31
32
33
34
35
else:
36
print ("\nInvalid input")
37
print("\nDo you want to do more: ")
choice=input("Enter you choice: ")
38
39

Transcribed Image Text:print("\nDo you want to do more: ")
choice=input ("Enter you choice: ")
# If user enters no it will stop else continue the program again
if(choice=="no"):
break
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 8 steps with 3 images

Knowledge Booster
Similar questions
- Please help me with this.arrow_forwardhelp 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 imagesarrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education