We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.