Ok, so you need an array of bits stored in code space. How big is this array? For an array of upto 3584 bits you could encode the bit positions differently to give you better performance. e.g. word_offset = (8 * byte_offset) & 0xff; bit_offset = (8 * byte_offset) >> 8; so you use: bit 0 if word 0 for bit_arr[0] bit 0 if word 1 for bit_arr[1] bit 0 if word 2 for bit_arr[2] . . . bit 0 if word 255 for bit_arr[255] bit 1 if word 0 for bit_arr[256] bit 1 if word 1 for bit_arr[257] bit 1 if word 2 for bit_arr[258] . . . bit 1 if word 255 for bit_arr[511] bit 2 if word 0 for bit_arr[512] bit 2 if word 1 for bit_arr[513] bit 2 if word 2 for bit_arr[514] . . . basically you use the top most 4 bit of the index to specify bit within word ensuring that these 4 bits are always in the range 0..13 and the remaining bits (to the right of these 4 bits) as the word index. an array of 3584 would be 4+8 bits (256 14 bit words) an array of 1792 would be 4+7 bits (128 14 bit words) an array of 7168 would be 4+9 bits (512 14 bit words) Regards Sergio Masci http://www.xcprod.com/titan/XCSB Optimising PIC compiler free for personal non-commercial use On Thu, 8 May 2008, 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 > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist