Computer Science
MATH 22 DAC Discrete Mathematics Algorithm Converts Decimal to Binary Program

math 22

De Anza College

MATH

Question Description

I don’t understand this Computer Science question and need help to study.

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.

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] ...
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

Hi! Kindly check i...

alormrz89 (1672)
New York University

Anonymous
Top quality work from this tutor! I’ll be back!

Anonymous
Heard about Studypool for a while and finally tried it. Glad I did caus this was really helpful.

Anonymous
Thank you! Reasonably priced given the quality

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4
Similar Questions
Related Tags