Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

The sum of z scores for a data set is ____.

Answered: 1 week ago

Question

Solve the following 1,4 3 2TT 5x- 1+ (15 x) dx 5X

Answered: 1 week ago