Approaching calculation optimization
This section is an approach. It means it doesn't contain all the advanced tips and tricks for programming optimizations, but contains the optimizations on pure calculation.
Generally, we design an idea, code a program, and then optimize it. It works fine for huge programs. For smaller ones, we can optimize while coding.
Note
Normally, our firmware is small and so I'd suggest that you consider this as a new rule: Write each statement keeping optimization in mind.
I could add something else right now: Don't kill the readability of your code with too many cryptic optimization solutions; I thought of pointers while writing that. I'll add a few lines about them in order to make you familiar with, at least, the concept.
The power of the bit shift operation
If I consider an array to store things, I almost always choose the size as a power of two. Why? Because the compiler, instead of performing the array indexing by using a CPU-intensive multiply operation, can use...