Question: Problem 2: You are going to do some conversions, from integer to binary and then from binary back to integer. This will give you a
Problem 2: You are going to do some conversions, from integer to binary and then from binary back to integer. This will give you a chance to practice with if elif else and while statements, as well as a little string slicing. Your Task You prompt for an integer, convert the integer to a binary number string (there is no type for actual binany numbers so we just represent it as a string). We then take the string and turn it back into a regular integer. Things to remember 1. If the integer is 0, then we are done since conversion back and forth of 0 is still 0. The progranm 2. If the integer is negative, then we probably don't know how to do it, so the program prints a message 3. Otherwise, we do the conversion of the integer to a binary string (a string of I's and 0's) and then simply prints a note saying it is 0 and quits. saying it is negative and quits. convert that same string back to an integer to make sure we did it right. Hints How do we get a binary string from an integer? The easiest method uses integer division by 2 on successive quotients and then collects the remainders. It is best illustrated by an example. Consider the decimal number 156. , 1 56 divided by 2 gives the quotient 78 and remainder 0. . 78 divided by 2 gives the quotient 39 and remainder 0. 39 divided by 2 gives the quotient 19 and remainder I . 19 divided by 2 gives the quotient 9 and remainder .9 divided by 2 gives the quotient 4 and remainder l . 4 divided by 2 gives the quotient 2 and remainder 0, . 2 divided by 2 gives the quotient 1 and remainder 0 . 1 divided by 2 gives the quotient 0 and remainder l
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
