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 BinaryNumberint length for creating a binary number of length length and
consisting only of zeros.
A constructor BinaryNumberString str for creating a binary number given a string. For
example, given the string 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 getDigitint index for obtaining a digit of a binary number given an index.
The starting index is 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 shiftRint 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 For example, the result of shifting places to the right should yield
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
