write the code in python Example binary conversion: 22/2 11 r 0 (this remainder is the least
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Example binary conversion: 22/2 11 r 0 (this remainder is the least significant binary digit) 11/2=5r1 5/2=2r1 2/2=1r0 1/2=0r1 pulling all the remainders together we get 10110 [check: 16 +4 + 2 = 22] THE PROBLEM: Write a program that takes in a positive integer as input, and outputs a string of 1's and O's representing the integer in binary. For an integer x, the algorithm is: LOOP: As long as x is greater than 0 comment: The conversion naturally starts at the least significant digit. To put the binary digits in the correct order, pre-pend each binary digit to a string that starts out empty. LOOP: OutputString x modulo 2 (remainder is either 0 or 1) + OutputString Assign x with x divided by 2 and repeat EXAMPLE OUTPUT: This program converts a user entered decimal number to binary. Enter a positive integer to convert to binary (0 or less to QUIT): 1 1 is 1 binary Example binary conversion: 22/2 11 r 0 (this remainder is the least significant binary digit) 11/2=5r1 5/2=2r1 2/2=1r0 1/2=0r1 pulling all the remainders together we get 10110 [check: 16 +4 + 2 = 22] THE PROBLEM: Write a program that takes in a positive integer as input, and outputs a string of 1's and O's representing the integer in binary. For an integer x, the algorithm is: LOOP: As long as x is greater than 0 comment: The conversion naturally starts at the least significant digit. To put the binary digits in the correct order, pre-pend each binary digit to a string that starts out empty. LOOP: OutputString x modulo 2 (remainder is either 0 or 1) + OutputString Assign x with x divided by 2 and repeat EXAMPLE OUTPUT: This program converts a user entered decimal number to binary. Enter a positive integer to convert to binary (0 or less to QUIT): 1 1 is 1 binary
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
An algorithm has been written in pseudocode to input some numbers. It only outputs any numbers that are greater than or equal to 100. The number 999 is not output and stops the algorithm. INPUT...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Stock W, X and Y have expected returns of 9.0%, 16.1% and 11.3% respectively. Based on this and the attached information, what is the expected return of your portfolio? Stock W X Y Number of Shares...
-
Selected transactions for the Basler Corporation during its first month in business are presented below: Sept. 1 Issued common shares for $20,000 cash. 2 Performed $9,000 of services on account for a...
-
The Internet of Things research paper discusses the network of physical objects that are embedded into electronics and computers that allow machines to communicate with each other. The Paper Write an...
-
In 2014, Javier Ramos decided to open seafood restaurants in California and Texas. Ramos claims that he was describing the crusted glaze applied to cooked seafood to his friend Ivan Murillo when...
-
Ians place sells pet supplies to dog and cat owners. To sell its products, the marketing department requires sales personnel to call on the pet store retailers within their assigned geographic...
-
A company is planning to manufacture snowboards. The fixed costs are $129 per day and the total costs are $5,897 per daily output of 18 boards. What is the average costs per board tend to as...
-
Susan and Jeff each makes deposits of 100 at the end of each year for 40 years. Starting at the end of th 41st year, Susan makes annual withdrawals of X for 15 years and Jeff makes annual withdrawals...
-
What metabolic pathways are intricately involved in the biosynthesis of PHA (Polyhydroxyalkanoate)?
-
Crystal Lake, Inc., has a total debt ratio of 0.23. Note: once you know the total debt ratio, you automatically also know the total equity ratio, as the total debt ratio + the total equity ratio =...
-
Prove that 2" < n! for all n 4, n e N. Prove that 2n - 3 2-2 for all n 5, n N.
-
Canadian Tire Corporation, Limited (Canadian Tire) is a family of companies that includes a retail segment and a financial services division, among others. The retail business is led by Canadian...
-
Bryan, a business development representative at Strong Co., took her client out for a dinner that cost $131.50 before taxes. If she paid taxes of $20.38 on the meal, calculate the tax rate?
-
Data: Purchased January 2006 Purchase Price $150,000 Land Value $ 40,000 Type Property: Four-Plex NOI Yr 1 $12,500 Yr 2 $13,200 Yr 3 $14,100 Loan $125,000 @ 8.0% for 30 years Calculate the amount of...
-
Global.asax is used for: a. declare application variables O b. all other answers are wrong O c. declare global variables O d. handle application events
-
Go to the LearnChemE screencast link for Chapter 13 (http://www.umich.edu/~elements/6e/13chap/learn-cheme-videos.html). (a) View one of the screencast 5- to 6-minute video tutorials and list two of...
-
Taken from California Professional Engineers Exam. The endothermic liquid-phase elementary reaction A + B 2C proceeds, substantially, to completion in a single steam-jacketed, continuous-stirred...
-
The catalytic reaction A B takes place within a fixed bed containing spherical porous catalyst X22. Figure P15-2B shows the overall rates of reaction at a point in the reactor as a function of...
-
Cumulative Normal distribution \(\Phi_{(\mu, \sigma)}\) and probability (a) \(X \sim \phi_{(0,1)}\); what is \(P(X \leq 1.43)\) ? (b) \(X \sim \phi_{(0,1)}\); what is \(P(X>1.43)\) ? (c) \(X \sim...
-
Inverse cumulative Normal distribution \(z\) (a) Find \(z_{0.05}\). (b) Find \(z_{0.95}\). (c) Let \(X \sim \phi_{(2,1)}\). Find \(a\) such that \(P(X \leq a)=0.05\). (d) Let \(X \sim \phi_{(2,1)}\)....
-
The Normal approximation (a) A discrete stochastic variable \(X\) has expected value \(\mu_{X}=3\) and \(\sigma_{X}=1.2\). Use the Normal approximation to find \(P(X \leq 4)\). (b) A continuous...
Study smarter with the SolutionInn App