MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / reverseBits

Method reverseBits

src/main/java/com/thealgorithms/maths/FFT.java:270–278  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

fftBitReversalMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected