Convert 0 to N by adding 1 or multiplying by 2 in minimum steps | Java program for the above approach ; Function to count number of set bits in N ; Stores the count of set bits ; If N is odd , then it a set bit ; Return the result ; Driver Code
import java . io . * ; class GFG { static int minimumAdditionOperation ( int N ) { int count = 0 ; while ( N > 0 ) { if ( N % 2 == 1 ) { count ++ ; } N = N >> 1 ; } return count ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( minimumAdditionOperation ( N ) ) ; } }