Cs260 Fall 2020 Lab 6 Base Conversion Using Arrays Your task is to develop a program that converts a positive integer from its base 10 representation into its equivalent representation to base 2. As inputs to the program, you specify the number to be converted and also the base to which you want the number converted. The program then converts the keyed-in number to the appropriate base and displays the result. The first step in developing such a program is to devise an algorithm to convert a number from base 10 to another base. An algorithm to generate the digits of the converted number can be informally stated as follows: A digit of the converted number is obtained by taking the modulo of the number by the base. The number is then divided by the base, with any fractional remainder discarded, and the process is repeated until the number reaches zero. The outlined procedure generates the digits of the converted number starting from the rightmost digit. See how this works in the following example. Suppose you want to convert the number 10 into base 2. Table 6.1 shows the steps that would be followed to arrive at the result. Number Number Modulo 2 Number / 2 10 0 5 5 2 0 1 Table 6.1 Converting an Integer from Base 10 to Base 2 The result of converting 10 to base 2 is, therefore, seen to be 1010, reading the digits of the "Number Modulo 2 column from the bottom to the top. To write a program that performs the preceding conversion process, you must take a couple of things into account. First, the fact that the algorithm generates the digits of the converted number in reverse order is not very nice. You certainly can't expect the user to read the result from right to left, or from the bottom of the page upward. Therefore, you must correct this problem. Rather than simply displaying each digit as it is generated, you can have the program store each digit inside an array. Then, when you've finished converting the number, you can display the contents of the array in the correct order. Second, you must realize that you specified for the program to handle conversion of numbers into bases 2 Here is the sample run: Number to be converted? 10 Base? 2 Converted number 1010