Problem 4 In this problem, develop an algorithm to convert a binary representation to its decimal value. That is, conver
Posted: Tue Jul 12, 2022 8:20 am
Problem 4 In this problem, develop an algorithm to convert a binary representation to its decimal value. That is, convert base 2 representation to base 10 representation. Given an input array of 0 and 1s, treated as binary representation of a number, calculate the decimal value of the number. For example, if the array is filled with 1 1 0 1, the algorithm should output 13. If the array is filled with 0 0 1 1, then the output should be 3. To understand the conversion, you can look at the provided document "Number system 1012 22s.pdf", or search online for relevant information. In general, if a binary number has n digits as did2d3...dn-1dn, it can be converted to decimal by formula d₁*2¹-1 + d₂*2 ² + d3*2¹-³ + ... dn-1*2¹ + dn *20. As another example, if the array is filled with 0 0 1 0 0 1 1 1 then the program should output 39 because 0*27 + 0*26 + 1*25 + 0*24 + 0*2³ + 1*2² + 1*2¹ + 1*2° =39. Develop flowchart for this algorithm Give pre-condition and post-condition for your algorithm. The algorithm takes as input an array, filled with Os and 1s, outputs the decimal value represented by the Os and 1s. O O O O You will need a loop to traverse the array. The array can be traversed from left to right or, from right to left. Here you should traverse from right to left. You will need to calculate the power of the base, i.e., 20 2¹ 2². Define a sub-algorithm named O O O power (base, n) which calculates the base to the power of n, i.e., base". Call this sub-algorithm in the main algorithm. In the main algorithm, if need to calculate 2 to power of n, don't write 2º, instead, call function power to calculate. o Implement sub-algorithm power using loop. Start your flowchart as shown in the following figure. The algorithm takes as input an array arr Save the flowchart as img_binary.jpg start arr[]