Question: 1) Write a C program that reads a hexadecimal value from the keyboard and then stores the value into an unsigned char variable. Read two
1) Write a C program that reads a hexadecimal value from the keyboard and then stores the value into an unsigned char variable. Read two int values p and n from the keyboard, where the values are less than 8. Change the initial hexadecimal value in the following way: Shift the n bits starting at position p, so that they form the n least significant bits of the result. The remaining bits of the result are set to 0. Display the result using printf %x.
n = 3;p=4;input: a= 1f ; output: 0x07
n = 2;p=5;input: a=0x12; output: 0x01
2) Repeat exercise 1 using variables of type unsigned int instead of unsigned char. Discuss the differences between the two implementations.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
