Question: ( C programming only) The left-shift operator can be used to pack four character values into a four-byte unsigned integer variable. Write a program that

(C programming only) The left-shift operator can be used to pack four character values into a four-byte unsigned integer variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned integer variable, assign the first character to the unsigned variable, shift the unsigned integer variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator. Repeat this process for the third and fourth characters. 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.

Desired output:

Enter the first character :K

Enter the second character :L

Enter the third character :M

Enter the fourth character :N

Result after replacing last 8 bits with K

75 = 00000000 00000000 00000000 01001011

Result after shifting 8 bits to the left

19200 = 00000000 00000000 01001011 00000000

Result after replacing last 8 bits with L

19276 = 00000000 00000000 01001011 01001100

Result after shifting 8 bits to the left

4934656 = 00000000 01001011 01001100 00000000

Result after replacing last 8 bits with M

4934733 = 00000000 01001011 01001100 01001101

Result after shifting 8 bits to the left

1263291648 = 01001011 01001100 01001101 00000000

Result after replacing last 8 bits with N

1263291726 = 01001011 01001100 01001101 01001110

Result after shifting 8 bits to the left

1280134656 = 01001100 01001101 01001110 00000000

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!