Question: ( Unpacking Characters from an Integer ) Using the right - shift operator, the bitwise AND operator and a mask, write function unpackCharacters that takes

(Unpacking Characters from an Integer) Using the right-shift operator, the bitwise AND operator and a mask, write function unpackCharacters that takes the unsigned int from Exercise 10.12 and unpacks it into four characters. To unpack characters from a four-byte unsigned int, combine the unsigned int with the mask 4278190080(11111111000000000000000000000000) and right shift the result 8 bits. Assign the resulting value to a char variable. Then combine the unsigned int with the mask 16711680(00000000111111110000000000000000). Assign the result to another char variable. Continue this process with the masks 65280 and 255. The program should print the unsigned int in bits before it's unpacked, then print the characters in bits to confirm that they were unpacked correctly.

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!