// Hadamard on qubit k
//
// n qubits, N = 2n amplitudes
//
unsigned long i = 0, j, k1 = 1LU << k; // k1 = 0...010...0, k'th bit = 1
while( i < N) { // i will have k'th bit = 0, j will have k'th bit = 1
j = i | k1; Complex t0 = a[i], t1 = a[j];
a[i] = s2*(t0+t1); a[j] = s2*(t0-t1);
++i; i += (i & k1); // skip i values with k'th bit = 1
}