Thanks, I just wonder what would be faster your method or this one? (I need this part to be executed as fast as passible)
Quit wondering. Test and see.
Use micros to record a start time. Call your function 10,000 times with different values. Use micors to record an end time. Compute the difference.
Use micros to record a start time. Call the bit shift method 10,000 times with different values. Use micors to record an end time. Compute the difference.
See for yourself which is faster.
The overhead of a function call, required in your method, will far outweigh the need to not calculate a value.
Of course, an array lookup could be even faster.
byte pows[] = {0, 2, 4, 8, 16, 32, 64, 128};
byte val = pows[6]; // will get 2^6.