Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 3.6- Create an option 5 to convert binary number to decimal. It should convert properly. Also, format the numbers to have multiple of 8
Python 3.6- Create an option 5 to convert binary number to decimal. It should convert properly. Also, format the numbers to have multiple of 8 characters as 0. For example , 11010 is 11010000. Provide indented source code with screenshot of output. Thanks def decToBin(num): binary = [] while (num > 0): a = int(float(num % 2)) binary.append(a) num = (num - a) / 2 binary.append(0) string = "" for j in binary[::-1]: string = string + str(j) return (string) def binToDec(binary): decimal = 0 for digit in binary: decimal = decimal * 2 + int(digit) return (decimal) def binAdd(): a = input("What is your first binary string? ") b = input("What is your second binary string? ") c = (binToDec(a)) + (binToDec(b)) return (decToBin(c)) def binSub(): a = input("What is your first binary string? ") b = input("What is your second binary string? ") c = (binToDec(a)) - (binToDec(b)) return (decToBin(c)) print("Option 1: Convert a decimal number to binary ") print("Option 2: Add two binary strings ") print("Option 3: Subtract two binary strings ") print("Option 4: Exit ") k = int(input("What would you like to do ? ")) if k == 1: print(decToBin(int(input("What is your number? ")))) elif k == 2: print(binAdd()) elif k == 3: print(binSub()) elif k == 4: quit()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started