Implement 16-digit inversion (Reverse Transformation)

Source: Internet
Author: User
Tags date1

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.