Relative Content

Tag Archive for c++performanceloopsbit-manipulation

Is bitwise shift more “efficient” than a for loop?

I just started going through “Data Structures and Algorithms in C++” and in one of the intro exercises they ask to write a function which returns powers of 2 and takes the exponent n
as an argument. They ask not to multiply 2 by itself n times as there are more efficient ways of doing it.