In certain memory systems the most common error is a single error and the n
est most common error is two errors in positions which are stored physicall
y adjacent in the memory. In this correspondence we present optimal codes f
ur recovering from such errors. We correct single errors and detect double
adjacent errors. For detecting adjacent errors we consider codes which are
byte-organized. In the binary ease, it is clear that the length of the code
is at most 2(r) - r - 1, where r is the redundancy of the code. We summari
ze the known results and some new ones in this case. For the nonbinary case
we show an upper bound, called "the pairs bound," on the length of such co
de. Over GF (3) codes with bytes of size 2 which attain the hound exist if
and only if perfect codes with minimum Hamming distance 5 over GF(3) exist.
Over GF (4) codes which attain the bound with byte size 2 exist for all re
dundancies. For most other parameters we prove the nonexistence of codes wh
ich attain the bound.