in-place bit-reversed shuffle on an array

前端 未结 7 1352
后悔当初
后悔当初 2020-12-05 08:50

For a FFT function I need to permutate or shuffle the elements within an array in a bit-reversed way. That\'s a common task with FFTs because most power of two sized FFT fun

7条回答
  •  余生分开走
    2020-12-05 09:35

    Element 00000001b should be swapped with element 10000000b

    I think you mean "Element 00000001b should be swapped with element 11111110b" in the first line?

    Instead of awapping 256 bytes you could cast the array to (long long*) and swap 32 "long long" values instead, that should be much faster on 64 bit machines (or use 64 long values on a 32 bit machine).

    Secondly if you naively run through the array and swap all values with its complement than you will swap all elements twice, so you have done nothing at all :-) So you first have to identity which are the complements and leave them out of your loop.

提交回复
热议问题