Q:

FFT reordering phase

I've got some code for you guys. 
This is the first step of the splitting algorithm for the Fast Fourier Transform.
What the algorithm should do is reorder the array such that every element on the input will be displaced in the "binary mirrored" position of the output.
For example, the element X[4] will be in position X[1], since the mirrored representation of 100 is 001.  
Till here, everything is clear. However, the algorithm that does such reordering is not. Atleast I have a hard time understanding.
What does the second, inner loop do?  
// N is the length of the array
// p is the number of bits needed to represent the index

for(int n=0; n<N; n++) {

   int j=0; 
   int m=n;
   for(int i=0; i<p; i++) {
     j = 2∗j + m%2; m = m/2;
   }

   if ( j>n) { 
     complex<double> h;
     h = X[j]; 
     X[j] = X[n]; 
     X[n] = h;
   }

}

A:

Think of an integer as being a sequence of bits.

j = 2j this pops the bit on the left and pushes zero into the right
m % 2 this obtains the right bit
m = m / 2 pops the bit on the right and pushes a copy of the leftmost bit on the left
j + x sets the rightmost bit of j to x, assuming that bit is currently zero and that x is 0 or 1

so all this is doing is popping bits off of the right of m and pushing them onto the right of j.

