Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

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
expand button
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
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
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education