Reverse processing of an 8-bit (one byte) number

Some time ago, the 8-bit parallel data port was accidentally connected in reverse order. In order not to change the hardware, the 8-bit 2 mechanism of the number of bytes obtained was reversed in the program, and the processed byte was returned. After continuous conciseness of the code, the algorithm of reverse order processing is attached below. I personally think that sometimes it is more useful, and netizens have other better algorithms to learn from!


unsigned char Convert_Byte(unsigned char Data) 
{
char i;
unsigned char Data1;
Data1 = Data;
Data = 0x00;

for(i = 0 ; i<(sizeof(char)*8/2) ; i++)
{
Data = Data | (Data1&(0X80>>i))>>(7-i*2);
Data = Data | (Data1&(0X01<<i))<<(7-i*2);
}

return  Data;

}

Guess you like

Origin blog.csdn.net/ludaoyi88/article/details/51240392