elp 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: "))
elp 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: "))
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6fd5cc9b-0f4a-4f78-a8ef-859031ebfbed%2F6ad240ca-63fb-47ba-aeea-f4c7ea7f426c%2Fkzx15f2_processed.png&w=3840&q=75)
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 step
Solved in 8 steps with 3 images

Recommended textbooks for you

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

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