Maker Pro
Maker Pro

integer averaging on the cheap

F

Fritz Oppliger

Jan 1, 1970
0
I want to average a number of 16bit integers. Never mind that 8051 basic
does not support unsigned integers, I would bust the 16 bit limit and
don't want to have to institute a whole multi-byte math trip just for this
one task, though it would no doubt be educational.
My crazy idea:
integers 0-7
i0Lo i0Hi
i1Lo i1Hi
i2Lo i2Hi etc.

How about treating all the hi and low bytes separately, as 8bit integer,
add them up and divide, then recombine their average?
It would have the advantage that the individual additions could be done
within 16 bits, and the division would bring it back within 8 bits.

Gotta try this...
 
Top