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
x in binary then swap b y t e s should return x
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 :
Number w i t h b y t e s swapped:
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
