Bit reversal of an integer, ignoring integer size and endianness

后端 未结 12 2341
既然无缘
既然无缘 2021-01-03 00:18

Given an integer typedef:

typedef unsigned int TYPE;

or

typedef unsigned long TYPE;

I have the following

12条回答
  •  萌比男神i
    2021-01-03 00:54

    In case bit-reversal is time critical, and mainly in conjunction with FFT, the best is to store the whole bit reversed array. In any case, this array will be smaller in size than the roots of unity that have to be precomputed in FFT Cooley-Tukey algorithm. An easy way to compute the array is:

    int BitReverse[Size]; // Size is power of 2
    void Init()
    {
       BitReverse[0] = 0;
       for(int i = 0; i < Size/2; i++)
       {
          BitReverse[2*i] = BitReverse[i]/2;
          BitReverse[2*i+1] = (BitReverse[i] + Size)/2;
       }
    } // end it's all
    

提交回复
热议问题