Question: Write a program BinaryChanger.java that accepts a 4 bit binary number as a String, and converts it into a decimal number. Description: Binary is the

Write a program BinaryChanger.java that accepts a 4 bit binary number as a String, and converts it into a decimal number. Description: Binary is the base-2 number system, so numbers are represented using two digits (0 or 1) instead of ten (0 through 9, i.e. decimal). In decimal, you have the one's place, ten's place, hundred's place, etc. where each place is a power of ten. In binary, each place is a power of two, so you have the one's place (20), two's place (21), four's place (22), etc.

Example:

Given the number 0101 here's how it is converted to decimal: 0101 = 23 * 0 + 22 * 1 + 21 * 0 + 20 * 1 = 8 * 0 + 4 * 1 + 2 * 0 + 1 * 1 = 5

Given the number 1111: 1111 = 23 * 1 + 22 * 1 + 21 * 1 + 20 * 1 = 8 * 1 + 4 * 1 + 2 * 1 + 1 * 1 = 15

Example Dialog:

Enter a four digit binary number (e.g. "0111") > 0101 0101 converted to decimal is 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!