Have you considered storing this in some sort of word-aligned manner... I.E. let's assume you want to store 500 8 bit bytes... Store the first 286 as bits 0...7 bits of each word (8 bits). Store the next 143 as bits 8..11 of each word, but spread across 2 words. Store the final 71 as bits 12 & 13 of eac word, and spread across 4 words. Then your algorithm looks like (semi pseudo-code, in c ... That is, don't shoot me if I mangled something like & versus && or >>'d the wrong way or too few/too many bits- I've had too long of a day today so I might have messed up and I don't feel like looking it up.) uint8 retrievebyte (uint16 address) { if (address<286) { return flash[address]&&0xff; } else if (address<(143+286)) { //return bits 8.11 of address*2 in lower 4 bits, and 8.11 of address*2+1 in higher 4 bits; return ( (flash[address*2]>>8) && 0x0f) + (flash[address*2+1]>>4&&0xf0) ); } else if (address<(71+143+286)) { return ( (flash[address*2]>>12) && 0x03) + (flash[address*2+1]>>10&&0x0c) + (flash[address*2+2]>>8&&0x30) + (flash[address*2+3]>>6&&0xc0) ); } else { /// Handle out of range error accordingly. return 0; } } Ed Sutton wrote: > Are there other ways to implement a divide by a 14 constant other than > cycle-chewing subtraction loops? > > I want to use the PIC16F flash consisting of 14-bit words to store 8-bit > data. I can implement the multiply-by-8 as a shift. The crux of the > problem is basically the divide by a constant of 14. > > Pseudo Code ( actual code will likely be assembly ) > > wordOffset = 8*byteOffset / 14; // The integer result > wordBitOffset = 8*byteOffset % 14; // The remainder result > > > Patterns: > > The 14-bit words and 8-bit data have a common multiple of 56. > The wordBitOffset pattern { 0,8,2,10,4,12,6 } repeats every 7-bytes. > I can't see a solution but it is an interesting puzzle. > > Thanks in advance for any tips or suggestions, > > -Ed > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist