On Sat, 19 May 2018, David C Brown wrote: > Use repeated subtraction of 100 to get the top nibble then use a 100 entr= y > lookup table for the two lower nibbles. Fast and compact. Yes I was just putting together some code to show this and you beat me to=20 it. Also take into account that the last two bits don't change with=20 repeated subtraction of 100 and you can speed the whole thing up by using 8 bit arithmetic instead of 16bit. e.g. // y =3D 0; // // while (x >=3D 100) // { // y++; // // x -=3D 100; // } // // res =3D (arr[y] << 8) | arr[x]; // // // 100 base 10 =3D 64 base 16 =3D 01100100 base 2 // // uint8 x8, pl, ph; // int16 res; // // convert 10 bit number to 8 bit number // x8 =3D x >> 2; // // ph =3D 0; // // while (x8 >=3D (100 >> 2)) // { // ph++; // x8 -=3D (100 >> 2); // } // // will always be 8 bits // pl =3D (x & 3) | (x8 << 2); // // 2 x 8 bit BCD packed into 16 bit variable // res =3D (arr[ph] << 8) | arr[pl]; // where arr =3D 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09 0x10, ... 0x19, 0x20, ... 0x29, .... 0x90, ... 0x99 Regards Sergio Masci > > > __________________________________________ > David C Brown > 43 Bings Road > Whaley Bridge > High Peak Phone: 01663 733236 > Derbyshire eMail: dcb.home@gmail.com > SK23 7ND web: www.bings-knowle.co.uk/dcb > > > > > *Sent from my etch-a-sketch* > > On 19 May 2018 at 17:25, Jean-Paul Louis wrote: > >> Wayne, >> With 9bit input and 10/11 bit output, a lookup table will be fast and >> inexpensive. >> >> Just a thought, >> Jean-Paul >> N1JPL >> >> On Fri, May 18, 2018, 6:53 PM Dwayne Reid wrote= : >> >>> Good day to all. >>> >>> I'm looking for a small, fast 9-bit binary-to-decimal conversion >>> routine. Somewhere between Scott Datallo's 8-bit-to-decimal and John >>> Payson's 16-bit-to-decimal routines. >>> >>> Input range is [0..511] in binary, output in BCD or >>> packed-BCD. Actual input range for this project is 0..399 but I >>> might as well try to get the full 9-bits of range. >>> >>> Short and fast if possible. >>> >>> I've been looking at PICLIST.com as well as my old email archives but >>> haven't seen anything that is both short and fast. >>> >>> Does anyone have something that they can share? >>> >>> Many thanks! >>> >>> dwayne >>> >>> -- >>> Dwayne Reid >>> Trinity Electronics Systems Ltd Edmonton, AB, CANADA >>> 780-489-3199 voice 780-487-6397 fax 888-489-3199 Toll Free >>> www.trinity-electronics.com >>> Custom Electronics Design and Manufacturing >>> >>> -- >>> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >>> View/change your membership options at >>> http://mailman.mit.edu/mailman/listinfo/piclist >>> >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> > --=20 > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .