# How to generate a SWAP of $N$ qubits?

I know that SWAP2 (swaps 2 qubits) gate looks like:

$$SWAP2=\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$

and SWAP3 gate looks like $$SWAP3=\begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix}$$

The question is, how do I generate SWAP of N qubits, SWAPN?
I need this for my Fourier transform algorithm.

It depends on context as to what it is you actually want to write down. For implementing in some sort of quantum circuit, the decompostion into pairwise swaps, as I've just given it, is probably ideal. Your question seems to imply that you want a matrix. In which case, $$\text{SWAPN}=\sum_{x\in\{0,1\}^N}|x\rangle\langle x^R|,$$ where $$x^R$$ is just the bit string $$x$$, reversed.
Depends on what you mean by SWAPN, that is what qubits are swapped. Your SWAP3 gate in Dirac notation is $$|000\rangle\langle 000|+|001\rangle\langle100|+|010\rangle\langle010|+|011\rangle\langle110|+|100\rangle\langle001|+|101\rangle\langle101|+|110\rangle\langle011|+|111\rangle\langle111|$$ that is the first and third qubits are swapped; assuming SWAPN means swapping first and N-th qubit, write SWAPN in Dirac notation and then convert it to matrix notation.