Power of Two

This was a fairly simple problem from Problem of the Day. My initial response in looking at the problem was to simply use a loop to multiply 1 by 2 incrementally. (Such as pow *=2.) But the trick in efficiency mentioned here is simply making use of logarithms. Java, as with many things makes this quite easy as shown below.

Back to top ▴