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.