Question: In this assignment we are going to somewhat step away from our Byte class for a moment and take a look at recursion. In the
In this assignment we are going to somewhat step away from our Byte class for a moment and take a look at recursion. In the Byte class you have functions called setValue and bitsToIn that use a loop to compute a value from the bits. These functions look like this:
void Byte::setValueint val
int mask ;
for int i ; i ; i
if val & mask
thisseti;
else
thisseti;
mask mask ;
return;
int Byte::bitsToInt const
int val ;
int mask ;
for int i ; i ; i
if thisati
val thisati mask;
mask mask ;
return val;
Your task is to write these as recursive functions but DO NOT use them in your Byte project. Simply create a main.cpp and two functions below it You should pass an array to these functions. In other words, your function prototypes should look something like this:
int bitsToIntint ar;
void setValueint ar int value;
The setValue function will simply fill the array with the correct bits. As an example, if value is you should fill the array with
The bitsToInt function will do the exact opposite. It will take the array of bits and covert it to a value. As an example, if array has the function will return
Write some simple code in main to test your recursion.
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
