Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Output must be exactly the same as image example. 10. (Packing Characters into an Integer) The left-shift operator can be used to pack four char-
Output must be exactly the same as image example.
10. (Packing Characters into an Integer) The left-shift operator can be used to pack four char- acter values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an un- stgned int variable, assign che first character to the unsigned int variable, shift the unsigned int 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 p gram should output the characters in heir bit format before and after they're packed into the un- signed int to prove that the characters are in fact packed correctly in the unsigned int variable. Do not use global variables. If your scanf is not waiting for your input, it is because it consumed the Carriage Return from the buffer remained from the previous scant. This only happens if you use %c in the scent. To remove left over Carriage Return in the buffer, use getchard); right after the scanfl"%c". Refer to slides that covered user input for further explanation. Information about packCharacter function Should not print any output. Should accept one character and the target integer that will be used for packing Should perfom the left shift and append the character to the target. Expected input and output. Enter the first character :lK Enter the second character :I Enter the third character :M Enter the forth characterN Result before shifting and replacing last 8 bits with K 0-00G0000G 00000000 0G000000 00000000 Result after shifting and replacing last 8 bits with K 75 0000 00000O 000001001011 Result before shifting and replacing last 8 bits with L 75 -00000G0G G00G0000 0000G0O0 01001011 Result after shifting and replacing last 8 bits with L 1927600000000 0000000 1001011 01001100 Result before shifting and replacing last 8 bits with M 19276 G00O000O 00000000 01001011 01001100 Result after shifting and replacing last 8 bits with M 4934733 -00000000 01001011 01001100 01001101 Result before shifting and replacing last 8 bits with N 4934733-00000000 01001011 01001100 01001101 Result after shifting and replacing last 8 bits with N 1263291726 01001011 01001100 01001101 01001110Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started