Question: Please code in C++ ONLY!! Please finish the code for void unpackCharacters(char characters[], unsigned pack) and void displayBits(unsigned value) from the code below!! -------------------------- For

Please code in C++ ONLY!!

Please finish the code for void unpackCharacters(char characters[], unsigned pack) and void displayBits(unsigned value) from the code below!!

--------------------------

For the assignment, we will be unpacking characters from unsigned integers. Using the right-shift operator, the bitwise AND operator and a mask, write function unpackCharacters that takes the unsigned integer packed, from the driver program, and unpacks it into four characters.

To unpack four characters from an unsigned four byte integer, combine the unsigned integer with the following masks:

mask1 4278190080 mask2 16711680 mask3 65280 mask4 255

and rightshift the result 8 bits. Assign the resulting value to a char variable. Then, combine the unsigned integer with the mask 255. Assign the result to another char variable. The program should print the unsigned integer in bits before its unpacked, then print the characters in bits to confirm that they were unpacked correctly.

For this assignment you will need to provide the functions that perform the following tasks:

a) unpackCharacters unpacks, or takes apart, the characters.

b) displayBits this function will print out (display) the bits.

---------------------------------------------------------------------------------------------

Given code:

#include #include

using namespace std;

// prototypes void unpackCharacters(char[], unsigned); void displayBits(unsigned);

int main() { char characters[4]; unsigned packed{1633903975}; // a, c, e, g

cout << "The packed character representation is: "; displayBits(packed);

// demonstrate unpacking of characters unpackCharacters(characters, packed); cout << " The unpacked characters are: "; for (size_t i{0}; i < 4; ++i) { cout << characters[i] << " "; } cout << endl;

cout << " The unpacked characters in bits are:" << endl; for (size_t i{0}; i < 4; ++i) { displayBits(characters[i]); } }

// take apart the characters void unpackCharacters(char characters[], unsigned pack) {

}

// display the bits of value void displayBits(unsigned value) {

}

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