Question: Convert a binary number to a decimal number (a whole number with base 10). Prompt the user to enter in a 4-digit binary number, read

Convert a binary number to a decimal number (a whole number with base 10). Prompt the user to enter in a 4-digit binary number, read it as a String, and convert it to a decimal. Each position of a binary number represents 2 raised to the corresponding power. Position numbers start at O from the right-most bit. For instance, 1011 can be converted by multiplying each bit value by 2 raised to the appropriate power: 1 * 213 +0* 2^2+1 * 211 + 1*240 = 1 *8+ 0* 4+ 1*2 + 1*1 = 8+2+1 = 11 Hint: You will need to extract each letter of the String using the charat method. Then, refer to an ASCII table to figure out a simple arithmetic expression to convert the char to the appropriate number, 0 or 1. You may use the power method in the Math package, but you do not need to - you may simply use 8, 4, 2, and 1 in the arithmetic. You may not use the Integer.parseInt or other automatic conversion methods. Note that we are intentionally constraining the solution we expect from you. This is to give you practice manipulating String and char objects. You would normally solve this problem using a built-in method like parseInt or by using Horner's rule to loop through the digits in the binary number to convert it to a decimal number. Grading: 10 points total 5 points via zy Books 4 points for the correct code with no 'advanced' methods like parseInt 1 point for documentation & style oe.g. proper indentation, good variable names with proper capitalization LAB ACTIVITY 20.2.1: a1, #2 Binary conversion 075 ConvertBinary.java Load default template... 1 # type your solution here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
