public class integerbinconstructor {
public static void main (String[] args){
integerbinconstructor test = new integerbinconstructor();
int N = 18;
System.out.println(test.solution(N));//6
System.out.println(test.solution(2147483647));
}
public int solution (int N){
int counter = 1;
if (N == 1){
return counter;
}
while (N > 1){
if (N % 2 == 0){
counter++;
N = N/2;
} else if ( (N - 1) % 2 == 0){
counter++;
N = N-1;
}
}
return counter;
}
}