 MATH 22 DAC Discrete Mathematics Algorithm Converts Decimal to Binary Program

Computer Science

math 22

De Anza College

MATH

### Question Description

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 , r , r , . . . , r [k]. Even if the initialvalue of q equals 0, the loop should execute one time (so that r  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 , r , . . . , r [i − 1] are all 0’s and 1’s, and a = (r [i − 1]r [i − 2] · · · r r r )2 .] Output: r , r , r , . . . , 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. Hi! Kindly check i... alormrz89 (2377)
New York University Anonymous
Awesome! Perfect study aid. Studypool 4.7 Trustpilot 4.5 Sitejabber 4.4