Hello everyone, I implemented a Moving average routine in Keil C51. And as I read else where that whenever I divide the number with 2^n the compiler uses shift operation, so that code is small and fast. And Compiler did optimize it in this condition:
average =BINHI/64; //BINHI, average is unsigned int.
However when BINHI is unsigned long instead of unsigned int the compiler uses actual division which is very costly in 8 bit. So is there any way to divide unsigned long using shift operations only, if I make sure divisor is 2^n.
Mann you are a life saviour. Shifting instead of division saved me like 200 bytes, (I am using silabs F350 MCU with nice peripherals but only 8K flash) it means a lot in my case. And especially your rounding technique, there's no way in hell I would have known that. A Really Big thanks to you.