Although Java does not have an operator for exponentiation y
Although Java does not have an operator for exponentiation, you can accomplish exponentiation using the Math.pow(base, exponent) method. For example, in the following statement System.out.println(Math.pow(2, 3)); the base is 2 and the exponent is 3, and since 2^3 = 8, the statement will print 8.0. (The data type of the value returned by Math.pow is always a double, i.e., double-precision floating point number) And the statement System.out.println(Math.pow(2, 2) + Math.pow(2, 3)); will print 12.0 since 2^2 + 2^3 = 4.0+ 8.0 = 12.0. Finally, the statement System.out.println(2 * Math.pow(16, 3) + 2 * Math.pow(16, 2)); will print 8704.0 because 2 times 16^3 + 2 times 16^2 = 2 times 4096.0 + 2 times 256.0 = 8704.0. Using the Math.pow(base, exponent) method, write System.out.println statements with appropriate expressions to convert each of the following to base 10: (11100)_2 (777)_8 (ABC)_16 (DEF)_16
Solution
System.out.println(Math.pow(2,4)+Math.pow(2,3)+Math.pow(2,2));
System.out.println((7*Math.pow(8,0))+(7*Math.pow(8,1))+(7*Math.pow(8,2)));
System.out.println((12*Math.pow(16,0)+(11*Math.pow(16,1))+(10*Math.pow(16,2)));
System.out.println((15*Math.pow(16,0))+(14*Math.pow(16,1))+(13*Math.pow(16,2)));
