查表法: INT8U ReversalTbl[] = {0x00, 0x08, 0x04, 0x0c, 0x02, 0x0a, 0x06, 0x0e, 0x01, 0x09, 0x05, 0x0d, 0x03, 0x0b, 0x07, 0x0f};
INT8U ReversalFun(INT8U input) { INT8U output; INT8U byte_h = Reversal[input / 16]; //高8位查表 INT8U byte_l = Reversal[input % 16]; // 低8位查表 output = byte_l * 16 + byte_h; //交叉代替 return output; }
移位法:(C51) INT8U bdata InData; sbit Bit_L = InData^0; INT8U ReversalFun(INT8U input) { INT8U i; INT8U output = 0; InData = input; for (i=0; i<8; i++){ output = output << 1; //输出数据初始为0,左移1位仍为0 output += (INT8U)Bit_L; InData = InData >> 1; } return output; }
|