Question: Define a class BinaryNumber that represents binary numbers and a few simple operations on them, as indicated below. The following operations should be supported: A

Define a class BinaryNumber that represents binary numbers and a few simple operations on
them, as indicated below.
The following operations should be supported:
A constructor BinaryNumber(int length) for creating a binary number of length length and
consisting only of zeros.
A constructor BinaryNumber(String str) for creating a binary number given a string. For
example, given the string "1011", the corresponding binary number should be created.
For this exercise you will have to use some standard String operations.
An operation int getLength() for determining the length of a binary number.
An operation int getDigit(int index) for obtaining a digit of a binary number given an index.
The starting index is 0. If the index is out of bounds, then a message should be printed
on the screen indicating this fact.
An operation int toDecimal() for transforming a binary number to its decimal notation (cf.
the example given above).
An operation void shiftR(int amount) for shifting all digits in a binary number any number of
places to the right, as indicated by a parameter amountToShift. The new digit should be 0. For example, the result of shifting 10113 places to the right should yield 0001011

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 Programming Questions!