Homework 00

Binary Changer

Due 09/15/2023 by 11:55PM

 

Objective:

 

Write a program that accepts two four-digit binary numbers, converts them to decimal values, adds them together, and prints both the decimal values and the result of the addition.

 

Requirements:

 

Hint:

A simple way to convert a binary value to a decimal value.

  1. Multiply each binary digit by its corresponding base 2 placement value.

 

Binary Digit

b0

b1

b2

b3

Base 2 Value

23

22

21

20

Result

b0 x 23

b1 x 22

b2 x 21

b3 x 20

 

Example:

 

Binary Digit

0

1

1

1

Base 2 Value

23

22

21

20

Result

0

4

2

1

 

  1. Add the values together to get the decimal value.

 

Binary Value = b0 x 23 + b1 x 22 + b2 x 21 + b3 x 20

Example:

 

Binary Value = 0 + 4 + 2 + 1 = 7

 

Finally:

Upload the solution’s source file (.JAVA extension) to the CSCE Dropbox