Question: Class Construction Create a class called BitsByte that will store one byte of data. C + + - You should create a header called BitsByte.h

Class Construction
Create a class called BitsByte that will store one byte of data.
C++- You should create a header called BitsByte.h, where the class definition will be placed. You should also have a corresponding .cpp file called Byte.cpp
Java - BitsByte should be a public class and should be in a file named BitsByte.java
Private Data:
From the supplemental material, you should have observed that a byte consists of 8 bits. To store these 8 bits of information, we are going to need an array. In the data section of the class create an array called bits that will hold 8-integer values to store the 1's and 0's for the Byte.
As an example, if we were to store the value 65 in the data section of our class, The int array will hold 01000001
Create the following utility function:
int bitsToInt()- this function will return the bit values stored in the data section as an int (whole number) value.
Public Methods:
Create the following functions / methods :
void setValue(int value)- this function will take as an argument an int type. The argument is going to be the value we want to set our bits to. To set the bits we are going to have to use some bitwise operators. Here is how it works.
A value like 65 has a binary value of
01000001
This will require you to create a loop and use AND along with the left shift operators to determine the value of each bit and store it in the array. Using bitwise operators is a requirement here.
int at(int index)- takes as an argument an int value called index. This function will return the bit located in the array at index. This value should be returned as an int.
string toString()- returns the array as a string. Please note that with binary values they are in the opposite order from the way we are storing them. The array has index 0 going from left to right and binary numbers has bit 0 to the right going right to left. This means you will have to reverse the array when creating the string.
int toInt()- This function will return the value in the array as a whole number. This function should call the private function bitsToInt.
Constructors
Your BitsByte class should have the following constructors
BitsByte(int* ar)- Sets the data section with the value found in the array. Note: the array should be a size of 8 and should hold a binary representation of a whole number
BitsByte(int val)- Sets the data section to val
BitsByte(string val)- Sets the value of the data section to the value found in val. Note: val should be a string representation of a binary number.
BitsByte()- Default constructor that sets the data section to 0

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!