I'm looking for an efficient way to generate all unordered pairs of bit strings (represented as integers) that have Hamming distance at most 2. In this answer, it is shown how this is quite efficiently done for pairs having Hamming distance 1.
In other words, the answer above gives us all edges of the hypercube graph. Phrased in these terms, I'm looking for an efficient way to generate the edges of the square of a hypercube.
Is there some nice known fast method, perhaps similarly based on bit tricks?