
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
please let anyone solve it!

Transcribed Image Text:Problem 3 (Decimal to Binary)
Write and test a function called decimal_to_binary() that takes a positive integer as input
argument and returns a string representing that number in binary. Your program should not use
the built-in bin() function for the conversion. You may use it to test your function to verify the
answers of your function.
The algorithm for decimal to binary conversion is as follows:
1. Let num be the input

Transcribed Image Text:2. Let p be the largest number that is power of 2 less than
or equal to num, and let output be ""
3. Repeat until p is 0:
3.1
If p < num, then subtract p from num and add a "1"
to the output
3.2
Otherwise add a "0" to the output
3.3
Divide p by 2
4. Return output
Note: you need to use your pow_of_two() function in step 2 of this algorithm.
Sample outputs:
decimal_to_binary (1) → "1"
decimal_to_binary(3) → "11"
decimal_to_binary(4) → "100"
decimal_to_binary(15) → "1111"
decimal_to_binary(20) → "10100"
decimal_to_binary(64) → "1000000"
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Can computers help decide sentences for criminals? If so, who should program the computer? What would Nils Christie say about using computers in this way? Note: I encourage you to interpret "computer" to mean all forms of artificial intelligence, including machine-learning. Do not limit yourself to current technology. I am asking whether we should do it, not whether computers are capable of it.arrow_forwardAccording to legend, the first century Jewish historian, Flavius Josephus,was captured along with a band of 40 compatriots by Roman soldiers duringthe Jewish–Roman war. The captured soldiers decided that they preferredsuicide to being captured and devised a plan for their demise. They wereto form a circle and kill every third soldier until they were all dead. Josephand one other decided they wanted no part of this and quickly calculatedwhere they needed to place themselves in the circle so that they would bothsurvive. Write a program that allows you to place n people in a circle andspecify that every m person will be killed. The program should determinethe number of the last person left in the circle. Use a circularly linked listto solve the problem.arrow_forwardA quaker was walking down a country road when he was suddenly confronted by a robber brandishing a pistol. The robber exclaimed, "Your money or your life!" My friend replied, "I cannot deliver my money because I should be aiding thee in evildoing, but exchange is lawful, and I will give thee my purse for the pistol." The thief consented to accept the purse, then the quaker pointed the gun to the robber's head and said, "Now buddy, give me back my pocketbook or the weapon may go off fire," according to the robber.arrow_forward
- Explain how the Constitutional right to free expression may come into conflict with the right to exclusive use of a trademark in the context of computer science. How can we ever reconcile these apparently irreconcilable differences?arrow_forwardBob uses the RSA cryptosystem to allow people to send him encrypted messages. He selects the parameters: p=3,q=17,e=3,d=11arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education