Question: ( a ) Use the bitwiseoperators towrite the following function: u n s i g n e d s h o r t s w

(a) Use the bitwiseoperators towrite the following function:
u n s i g n e d s h o r t s w a p _ b y t e s ( u n s i g n e d s h o r t i ) ;
s w a p _ b y te s should return the number that results from swapping the two bytes in i.
(Short integers occupy two bytes on most computers.) For example, if i has the value
0x1234(0001001000110100 in binary), then swap b y t e s should return 0x3412
(0011010000010010 in binary). Test your function by writing a program that reads a num
ber in hexadecimal, then writes the number with its bytes swapped:
E n t e r a h e x a d e c im a l number (up t o f o u r d i g i t s ) : 1234
Number w i t h b y t e s swapped: 3412
Hint: Use the %hx conversion toread and write the hex numbers.
(b) Condense the swap b y t e s function so that its body is a single statement]

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 Programming Questions!