One Algorithm
Unsigned short SwapBit16 (unsigned short Data)
{
Int I;
Unsigned short Dest;
Dest = 0;
For (I = 0; I <8; I ++)
Dest | = (Data & (1 <I ))? 1-0) <(15-i) + (Data & (1 <(15-i )))? 1-0) <I ));
Return Dest;
}
The above function is used to reverse the 16-digit (inverted transformation ).
You can use the following method to test the implementation.
This is a test function.
# Include <stdio. h>
Int main (void)
{
Int I;
Unsigned short Data = 45918;
Int Dest = 0;
For (I = 0; I <8; I ++ ){
Printf ("Date1 is 0x % x \ n", (Data & (1 <I ))? 1-0) <(15-I )));
Printf ("Date2 is 0x % x \ n", (Data & (1 <(15-i )))? 1-0) <I ));
Printf ("Date2 and Date1 is 0x % x \ n", (Data & (1 <I ))? 1:0) <(15-i) + (Data & (1 <(15-i )))? 1-0) <I ));
Dest | = (Data & (1 <I ))? 1-0) <(15-i) + (Data & (1 <(15-i )))? 1-0) <I ));
}
Printf ("the 0b1011001101011110 end the Date is 0x % x \ n", Dest );
Return Dest;
}
The test result is as follows:
Date1 is 0x0
Date2 is 0x1
Date2 and Date1 is 0x1
Date1 is 0x4000
Date2 is 0x0
Date2 and Date1 is 0x4000
Date1 is 0x2000
Date2 is 0x4
Date2 and Date1 is 0x2004
Date1 is 0x1000
Date2 is 0x8
Date2 and Date1 is 0x1008
Date1 is 0x800
Date2 is 0x0
Date2 and Date1 is 0x800
Date1 is 0x0
Date2 is 0x0
Date2 and Date1 is 0x0
Date1 is 0x200
Date2 is 0x40
Date2 and Date1 is 0x240
Date1 is 0x0
Date2 is 0x80
Date2 and Date1 is 0x80
The 0b1011001101011110 end the Date is 0x7acd
The result shows that the implementation idea is 15 <--> 2 ,...... 8 <--> 7. How to Implement the swap? You can analyze it in depth ..
From: gududesiling's column