标题:
8bit位倒序函数
[打印本页]
作者:
wxg1988
时间:
2013-1-14 12:41
标题:
8bit位倒序函数
#include
union
{
struct
{
unsigned char bit0 : 1;
unsigned char bit1 : 1;
unsigned char bit2 : 1;
unsigned char bit3 : 1;
unsigned char bit4 : 1;
unsigned char bit5 : 1;
unsigned char bit6 : 1;
unsigned char bit7 : 1;
}bits;
unsigned char ucOne8Byte;
}uData8;
void DataChange(unsigned char *upByte)
{
unsigned char bTemp;
uData8.ucOne8Byte = *upByte;
bTemp = uData8.bits.bit0;
uData8.bits.bit0 = uData8.bits.bit7;
uData8.bits.bit7 = bTemp;
bTemp = uData8.bits.bit1;
uData8.bits.bit1 = uData8.bits.bit6;
uData8.bits.bit6 = bTemp;
bTemp = uData8.bits.bit2;
uData8.bits.bit2 = uData8.bits.bit5;
uData8.bits.bit5 = bTemp;
bTemp = uData8.bits.bit3;
uData8.bits.bit3 = uData8.bits.bit4;
uData8.bits.bit4 = bTemp;
*upByte = uData8.ucOne8Byte;
}
int main()
{
unsigned char a = 0xfe;
DataChange(&a);
printf("0x%x\n", a);
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0