Computer Science
De Anza College Creating a Program for Algorithm that Converts Decimal to Binary

De Anza College

Question Description

I’m trying to study for my Computer Science course and I need some help to understand this question.

Project 1

The following algorithm converts decimal to binary using repeated division by 2.

Write a program using any programming language to execute repeated division by 2.

Project 2

The following algorithm is division algorithm. Write a program using any programming language for division algorithm.


Unformatted Attachment Preview

The following algorithm converts decimal to binary using repeated division by 2. Write a program using any programming language to execute repeated division by 2. Input: n [a nonnegative integer] Algorithm Body: q := n, i := 0 [Repeatedly perform the integer division of q by 2 until q becomes 0. Store successive remainders in a one-dimensional array r [0], r [1], r [2], . . . , r [k]. Even if the initialvalue of q equals 0, the loop should execute one time (so that r [0] is computed ). Thus the guard condition for the while loop is i = 0 or q  = 0.] while (i = 0 or q  = 0) r [i] := q mod 2 q := q div 2 [r [i] and q can be obtained by calling the division algorithm.] i := i + 1 end while [After execution of this step, the values of r [0], r [1], . . . , r [i − 1] are all 0’s and 1’s, and a = (r [i − 1]r [i − 2] · · · r [2]r [1]r [0])2 .] Output: r [0], r [1], r [2], . . . , r [i − 1] [a sequence of integers] The following algorithm is division algorithm. Write a program using any programming language for division algorithm. Division Algorithm [Given a nonnegative integer a and a positive integer d, the aim of the algorithm is to find integers q and r that satisfy the conditions a = dq + r and 0 ≤ r < d. This is done by subtracting d repeatedly from a until the result is less than d but is still nonnegative. 0 ≤ a − d − d − d − · · · − d = a − dq < d. The total number of d’s that are subtracted is the quotient q. The quantity a − dq equals the remainder r .] Input: a [a nonnegative integer], d [a positive integer] Algorithm Body: r := a, q := 0 [Repeatedly subtract d from r until a number less than d is obtained. Add 1 to q each time d is subtracted.] while (r ≥ d) r := r − d q := q + 1 end while [After execution of the while loop, a = dq + r .] Output: q, r [nonnegative integers] ...
Purchase answer to see full attachment
Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

The soluti...

uoscar (4178)
Rice University

Anonymous
I was on a very tight deadline but thanks to Studypool I was able to deliver my assignment on time.

Anonymous
The tutor was pretty knowledgeable, efficient and polite. Great service!

Anonymous
I did not know how to approach this question, Studypool helped me a lot.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4
Similar Questions
Related Tags