TITLE: Filling $4 \times 4$ matrix with Boolean values
QUESTION [19 upvotes]: In how many ways can we fill a $4 \times 4$ matrix with only $0$'s and $1$'s such that all columns and rows contain an odd number of $1$'s?

I did it in the following way:
I can fill the $3 \times 3$ gray area in $2^9 = 512$ ways and then adjust the entries in the yellow regions such that each row and each column eventually contains an odd number of $1$'s. 

Then I observed the following:

Region A and B, the sum of bits in each of the regions must be odd. Therefore both yellow regions must be either odd or even at the same time. So, there is no conflict in the left bottom corner position. Finally, my answer is $512$. Is it correct?
I would like to know other counting technique for this particular problem. 
Thanks!

REPLY [5 votes]: I would solve this question as follows. Since every column must contain an odd number of $1$'s, the number of $1$'s is restricted to $4$, $6$, $8$, $10$ and $12$. We only need to distinguish three cases, since $4$ and $12$ and $6$ and $10$ are each other's inverse. Distinguishing three cases:

Four $1$'s. Every column and row contains exactly one $1$, so the number of possible arrangements equals: $$4! = 24$$
Six $1$'s. One column contains three $1$'s, the three others contain one $1$. Once the former $1$'s have been placed in the grid, either all three remaining $1$'s are placed in the empty row and columns, or one $1$ is placed in the empty row and columns, and two $1$'s are placed in one of the non-empty rows. The number of possible arrangements thus equals: $${4 \choose 1}{4 \choose 3}\bigg(1+{3 \choose 1}{3 \choose 2}\bigg) = 4 \cdot 4 \cdot (1 + 3 \cdot 3) = 160$$
Eight $1$'s. Two columns contain three $1$'s and two columns contain one $1$. The six $1$'s must be distributed over all rows, otherwise it is impossible to have the three rows contain an odd number of $1$'s. Once these $1$'s have been placed in the grid, the remaining two $1$'s must be placed in the rows which contain two $1$'s. As such, the number of possible arrangements equals: $${4 \choose 2}{4 \choose 3}{3 \choose 2}{2 \choose 1} = 6 \cdot 4 \cdot 3 \cdot 2 = 144$$

The total number of arrangements thus equals:
$$24 + 160 + 144 + 160 + 24 = 512$$