This function reverses the bits of a number. It is used in Cooley-Tukey FFT algorithm. E.g. num = 13 = 00001101 in binary log2n = 8 Then reversed = 176 = 10110000 in binary More info: https://cp-algorithms.com/algebra/fft.html https://www.geeksforgeeks.org/write-an-efficient-c-program-to-r
(int num, int log2n)
| 268 | * @return The reversed number |
| 269 | */ |
| 270 | private static int reverseBits(int num, int log2n) { |
| 271 | int reversed = 0; |
| 272 | for (int i = 0; i < log2n; i++) { |
| 273 | if ((num & (1 << i)) != 0) { |
| 274 | reversed |= 1 << (log2n - 1 - i); |
| 275 | } |
| 276 | } |
| 277 | return reversed; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * This method pads an ArrayList with zeros in order to have a size equal to |