Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must Run and compile in Netbeans You cannot use any other library functions than

ID: 3640241 • Letter: M

Question

Must Run and compile in Netbeans

You cannot use any other library functions than mod % and power pow!

Write a function that converts a binary number into an equivalent decimal number. Moreover, write a program and test your function for the following values. 11000101,10101010,11111111,10000000,1111100000


HINT:

int 11 % 10 is 1 ---> last bit value

Thus, you have obtained the last bit value to which you will apply pow(2, weight) and subtotal it to the decimal value

int 11 / 10 is 1 ---> next binary number that you pass to the recursive call

Explanation / Answer

PS: Please rate the answer. public class Binary2Decimal { public static void main(String args[]) { int bin1[] = {1,1,0,0,0,1,0,1}; int bin2[] = {1,0,1,0,1,0,1,0}; int bin3[] = {1,1,1,1,1,1,1,1}; int bin4[] = {1,0,0,0,0,0,0,0}; int bin5[] = {1,1,1,1,1,0,0,0,0,0}; System.out.println("Binary is "); print(bin1); System.out.println("Integer is "); System.out.println(Bin2Dec(bin1)); System.out.println(" "); System.out.println("Binary is "); print(bin2); System.out.println("Integer is "); System.out.println(Bin2Dec(bin2)); System.out.println(" "); System.out.println("Binary is "); print(bin3); System.out.println("Integer is "); System.out.println(Bin2Dec(bin3)); System.out.println(" "); System.out.println("Binary is "); print(bin4); System.out.println("Integer is "); System.out.println(Bin2Dec(bin4)); System.out.println(" "); System.out.println("Binary is "); print(bin5); System.out.println("Integer is "); System.out.println(Bin2Dec(bin5)); } private static void print(int[] bin) { for(int i = 0; i