Diagonalizable matrices in $M_{2\times 2}(\mathbb{F}_2)$ List all diagonalizable $2\times 2$ matrices over the a field $F$ consisting of two elements $0$ and $1$.
I want to try and do this using C++, but perhaps this isn't the place to ask. I have an idea as to how I'd do it.

If $M$ is diagonalizable, we have $M=PDP^{-1}$ with $D$ diagonal. Since $D^2=D$, we get $M^2=M$. Conversely, if $M^2=M$, $M$ is annihilated by $X^2-X=X(X-1)$ which has simple roots and splits over $\mathbb{F}_2$. So $M$ is diagonalizable.
Hence the diagonalizable matrices are exactly the idempotents, i.e. $M$ such that $M^2=M$. This gives three possibilities for the minimal polynomial of $M$: $X$, $X-1$, and $X^2-X$. In the latter case, it must be equal to the characteristic polynomial as well. 
We get the null and the identity matrix with the first two cases, and the matrices whose characteristic polynomial is $X^2-X$ in the last case. The latter correspond to the matrices $M$ with $\mbox{trace} \;M=1$ and $\det M=0$:
$$
M=\pmatrix{a&b\\ c&d}\qquad a+d=1\qquad ad-bc=0.
$$
This leaves a few cases to consider and this gives in the end eight diagonalizable matrices:
$$
\pmatrix{0& 0\\0&0}\;\pmatrix{1& 0\\0&1}\;\pmatrix{1& 0\\0&0}\;\pmatrix{1& 1\\0&0}\; \pmatrix{1& 0\\1&0}\;\pmatrix{0& 0\\0&1}\;\pmatrix{0& 0\\1&1}\;\pmatrix{0& 1\\0&1}.
$$
Conclusion: $50\%$ of the matrices are diagonalizable in $M_2(\mathbb{F}_2)$.
