How to calculate log base 2 of an Integer in Java?

Given an integer N, the task is to calculate its log to the base 2, i.e. log2 N in Java.

Examples:

Input: N = 2
Output: 1

Input: 1024
Output: 10

Approach: