Check out http://en.wikipedia.org/wiki/Hamming_code under the heading "Hamming(11,7) code" One of the many advantages of the hamming code is that the parity bits tell you which bit is corrupted. If you follow the code as originally designed (parity bits spread throughout the data, not grouped together) then they tell you numerically which bit is bad. This may also be done with your particular implementation, but not quite as conveniently, if I understand correctly. You say the first four bits are parity, but don't tell us what each parity bit checks for. This is key to developing a function that corrects the error. However, one can determine this since you've given us several of the codes: P3 P2 P1 P0 D3 D2 D1 D0 P3 checks D0, D2, D3 P2 checks D0, D1, D3 P1 checks D0, D1, D2 P0 checks D1, D2, D3 The general solution to this sort of problem is to receive the data, re-compute the parity of the data portion, and then by comparing the computed parity against the received parity the error location can be discovered. If you understand the math then a simple calculation tells you the location of the error, if not then a table can be used, or a more complex calculation. Alternately, the brute force version simply checks the parity. If it doesn't match, then it goes through the data changing one bit at a time and checks the parity each time. If it finds one correctly, then you've found the single bit error. If it goes through all the bits once and doesn't find it then you've determined that two bits have changed. This takes longer than a calculation or table method (though may take less code space), but is trivial to implement regardless of the particular parity implementation. I am certainly no expert in this area (ie, read with grain of salt), but hopefully you find this helpful. -Adam On 11/1/07, Brooke Clarke wrote: > Hi: > > I'm looking for code to receive a serial data stream using a modified Hamming. > The coding for the digits 0 to 9 looks like: > 0 0000 0000 > 1 1110 0001 > 2 0111 0010 > 3 1001 0011 > 4 1011 0100 > 5 0101 0101 > 6 1100 0110 > 7 0010 0111 > 8 1101 1000 > 9 0011 1001 > The first nibble is parity and the second nibble is the number. > > The modified Hamming code can correct a one bit error and detect but not > correct a two bit error. The PIC code for the receiver would do the error > correction or detection and set a flag if the error could not be corrected. > > -- > Have Fun, > > Brooke Clarke > http://www.PRC68.com > http://www.precisionclock.com > http://www.prc68.com/I/WebCam2.shtml 24/7 Sky-Weather-Astronomy Cam > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Moving in southeast Michigan? Buy my house: http://ubasics.com/house/ Interested in electronics? Check out the projects at http://ubasics.com Building your own house? Check out http://ubasics.com/home/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist