> Lawrence Lile wrote: > > > > Anybody got a good averaging algorithm? > > > > [snip] > > > > > Best Regards, > > > > Lawrence Lile > > > Lawrence > > Try adding sixteen numbers and then shift right four bits > same effect as averaging the sixteen numbers or for more accurate > averaging add 256 numbers and then shift right by 8 (averaging 256 > numbers) --- need to watch for overflowing the accumulator though. > > regards Dave > Before shifting you could add half the value you are dividing with (8 in case of 16 numbers) to get it rounded. Without rounding, 15 ones and 1 zero would result in an average of 0 instead of 1. ------------------------------------ Ruben Jonsson AB Liros Elektronik Box 9124 200 39 Malmo Sweden Tel +46 40 14 20 80 Mail: ruben@sbbs.se ------------------------------------