8位bit高低位交换
0xab--->0xba
unsigned char reverseByte(unsigned char data)
{
unsigned char temp = 0x00;
for (unsigned char i = 0; i < 8; i++)
{
temp = ((data >> i) & 0x01) | temp;
if (i < 7)
{
temp = temp << 1;
}
}
return temp;
}
16位字节高低交换
0xab 0xcc----->0xcc 0xab
//0x45 0x67--->0x67 0x45
void changeBit(unsigned char*src,unsigned char*dst,int len) {
for (int i = 0; i < len; i+=2) {
if (i < len - 1) {//如果i在倒数第二个位置之前
dst[i] = src[i + 1];
dst[i + 1] = src[i];
}
}
}