/ Published in: C#
Reverse bit order of a byte variable, e.g. 0000 0001 (0x01) --> 1000 000 (0x80).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Add as static field of a Class static byte[] _RevBitsTable = { 0x00,0x08,0x04,0x0C, 0x02,0x0A,0x06,0x0E, 0x01,0x09,0x05,0x0D, 0x03,0x0B,0x07,0x0F }; //Add as method of a Class static byte ReverseBits(byte data) { byte ln = _RevBitsTable[data & 0x0F]; byte hn = _RevBitsTable[(data >> 4) & 0x0F]; return (byte)((ln << 4) | hn); }