In message <42543516.8095.63A48D@generic.my-fqdn.de> "Andrew Warren" wrote: > Just wrote this for a friend who needed to do simple error- > correction. I've previously posted (4,7) Hamming encode/decode > routines in assembly language, but he needed it in C, so... Nicely done.. Only one thing though: > const uint8 fixbits[8] = {0x00, 0x90, 0xA0, 0x81, > 0xC0, 0x82, 0x84, 0x88} > > uint8 receive(uint8 x) > { > return x ^ fixbits[(encode[x & 0x0F] ^ x) >> 4]; > } You're declaring fixbits as an 8-byte array. That means your array elements are numbered 0 to 7. Now, if x = 10 (say), because you're ANDing by 0x0F (to get the low nibble), this code will try and get the low 4 bits (range 0-15), meaning it'll try and get entry 10 from fixbits[8]. Which doesn't exist. End result? The program jumps off into never-never land. If I'm right (not sure if I am or not...) then this line: return x ^ fixbits[(encode[x & 0x0F] ^ x) >> 4]; should be changed to return x ^ fixbits[(encode[x & 0x07] ^ x) >> 4]; (change: ^^^^^^) I'll have a quick look at the code later... it looks like it'll compile under gcc on Linux pretty painlessly. Later, -- Phil. | Acorn Risc PC600 Mk3, SA202, 64MB, 6GB, philpem@philpem.me.uk | ViewFinder, 10BaseT Ethernet, 2-slice, http://www.philpem.me.uk/ | 48xCD, ARCINv6c IDE, SCSI ... "Bother", said Pooh, as he accidentally deleted his message base. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist