Question: The code is to be written in C++. I amn supposed to run it in linux machine. Question: Using shifting and masks instead of unions
The code is to be written in C++. I amn supposed to run it in linux machine.
Question: Using shifting and masks instead of unions find a way to pack four unsigned chars into an unsigned int and a way to later extract the four unsigned chars. You can use the union technique and the writeBitsInInt() function to test your code.
I have attached a code which uses Union to do the same job for reference or help.
The type char is itself a type of integer, but with only 8 bits. We could pack four unsigned char into an unsigned int. One method to achieve this is to use a union. The types in a union occupy the same space in memory. Consider the following example: >$ cat packUIntUnion.cpp #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
