A method of encoding data for error correction, comprising:
- providing a first set of data and a second set of data of equal length;
- organizing said first set of data into a first plurality of subsets and said second set of data into a corresponding plurality of subsets, each of said subsets comprising an equal number of data bits, wherein the logical values of said data bits within each of said subsets forms a logical pattern;
- comparing each bit within said first plurality of subsets which has a preselected logical value to its corresponding bit, wherein each of said bits which has a difference in logical value with its corresponding bit is an error bit and each subset within said first plurality of subsets containing at least one error bit is an error subset, the logical pattern of bits in said error subset being an error pattern;
- matching said error subsets and said corresponding subsets to select an encoding pattern, said matching step comprising:
- sorting each of said error subsets according to the logical pattern of its corresponding subset;
- selecting a first logical pattern within said corresponding subsets which has the largest number of error subsets containing different error patterns to translate to a second logical pattern, and selecting a primary set of encoding patterns capable of said translation of said first logical pattern to said second logical pattern;
- determining the logical pattern within said corresponding subsets which has the largest number of a single error pattern to translate to a logical pattern capable of correcting said single error pattern, and selecting a second set of encoding patterns from said primary set of encoding patterns capable of said translation;
- repeating said determining step for each of said logical patterns within said corresponding subsets which has an associated error subset until a single encoding pattern is selected from said primary set of encoding patterns;
- translating each of said subsets within said corresponding plurality of subsets into an encoded subset according to said selected encoding pattern to obtain an encoded set of data;
- wherein said encoding pattern is selected from the set of all possible reversible translation patterns for the possible logical combinations of bits in a subset containing said number of data bits;
- wherein said correction of said error bits comprises translating its corresponding bit to have a logical value equal that of said error bit according to said selected encoding pattern;
- and
- wherein said encoding pattern is selected to maximize the number of error bits corrected.