Objective:
In this assignment, you will do some bit-level operations, commonly used in
system programming.
DESCRIPTION
Part-1
------
- The left-shift operator can be used to pack two characters values into an
unsigned integer variable. Write a program that inputs two characters from
the keyboard and passes them to function packCharacters().
- To pack two characters into an unsigned integer variable, assign the first
character to the unsigned variable, shift the unsigned variable left by 8 bit
positions and combine the unsigned variable with the second character using
the bitwise inclusive-OR operator.
- The program should output the characters in their bit format before and after
they are packed into the unsigned integer to prove that the characters are in
fact packed correctly in the unsigned variable.
Part-2
------
- Using the right-shift operator, the bitwise AND operator and a mask, write a
function unpackCharacters that takes the unsigned integer from first part and
unpacks it into two characters. To unpack two characters from an unsigned
integer, combine the unsigned integer with the mask 65280 (11111111 00000000)
and right-shift the result 8 bits. Assign the resulting value to a char variable.
- Then, combine the unsigned integer with the mask 255 (00000000 11111111). Assign
the result to another char variable. The program should print the unsigned integer
in bits before it is unpacked, then print the characters in bits to confirm that
they were unpacked correctly.
DisplayBits(unsigned value) function:
- Write a separate function, which displays unsigned number in bits. This function
can be used whenever you have to display the number in bit form.
Hints: '<<' is the left shift operator and '>>' is the right shift operator in C.
'|' (vertical split bar) is bitwise OR and '&' is bitwise AND operator.
'^' is Exclusive-OR and '~' is not operator
## Deliverables
1) Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.
2) Exclusive and complete copyrights to all work purchased. (No GPL, GNU, 3rd party components, etc. unless all copyright ramifications are explained AND AGREED TO by the buyer on the site per the coder's Seller Legal Agreement).
## Platform
Unix