Efficient Algorithm for Bit Reversal (from MSB->LSB to LSB->MSB) in C

后端 未结 26 1351
情深已故
情深已故 2020-11-22 06:08

What is the most efficient algorithm to achieve the following:

0010 0000 => 0000 0100

The conversion is from MSB->LSB to LSB->MSB. All bits

26条回答
  •  粉色の甜心
    2020-11-22 06:54

    Implementation with low memory and fastest.

    private Byte  BitReverse(Byte bData)
        {
            Byte[] lookup = { 0, 8,  4, 12, 
                              2, 10, 6, 14 , 
                              1, 9,  5, 13,
                              3, 11, 7, 15 };
            Byte ret_val = (Byte)(((lookup[(bData & 0x0F)]) << 4) + lookup[((bData & 0xF0) >> 4)]);
            return ret_val;
        }
    

提交回复
热议问题