Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
