Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem (Decimal equivalent of binary number) A binary number is a sequence of 0's and 1's. 00001001 is a binary number. It is a sequence

Problem

(Decimal equivalent of binary number)

A binary number is a sequence of 0's and 1's. 00001001 is a binary number. It is a sequence of 8 zeros

and ones. The position of a binary digit is counted from 0 starting from the right most digit, like

Position

76543210

Binary number

00001001

To convert a binary number to its decimal equivalent,

decimal number =

binary-digit * 2

position

For example, for the binary 2

0

number 00001001,

Decimal number= 1* 2

0

+ 0 * 2

1

+ 0*2

2

+ 1*2

3

+ 0 *2

4

+ 0*2

5

+ 0*2

6

+ 0*2

7

= 1

+ 0

+ 0

+ 8

+ 0

+ 0

+ 0

+ 0

= 9

Requirements

1.

Develop a Java program that

a.

Reads a binary number as a string

b.

Computes its decimal equivalent as described above

c.

Displays both the binary number and its decimal equivalent as

Binary number: bbbbbbbb

Equivalent to:

Decimal number: ddddd

2.

Test your program for the following test cases and write your test observation at the end of your

source code as a block comment.

a.

Test case 1: 00000000

equivalent to

0

b.

Test case 2: 11111111

equivalent to

255

c.

Test case 3: 10101010

equivalent to

170

Note: Make your code flexible enough. All controls should be dependent on the length of the input

string.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

What are the strengths and limitations of cost-benefit analysis?

Answered: 1 week ago