Given a vector of bits v, compute the collection of bits that have Hamming distance 1 with v, then with distance 2, up to an input paramet
If Hamming distance h(u, v) = k, then u^v has exactly k bits set. In other words, computing u ^ m over all masks m with k bits set gives all words with the desired Hamming distance. Notice that such set of mask does not depend on u.
That is, for n and t reasonably small, precompute sets of masks with k bits set, for all k in 1,t, and iterate over these sets as required.
If you don't have enough memory, you may generate the k-bit patterns on the fly. See this discussion for details.