A coding strategy by weighted bits and a recursive algorithm of obtaining theweights for bidirectional associative memories are presented in the paper. This strategy modifiesKosko’s bidirectional associative memories matching patterns by Hamming distance into those byweighted Hamming distance so that ill structured sample pattern set without continuity can also bestored well. It is manifested that this method has high performance and practicability through storing and associating binary pixel patterns with computer simulations.