Convert 0 to N by adding 1 or multiplying by 2 in minimum steps | C # program for 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
using System ; public class GFG { static int minimumAdditionOperation ( int N ) { int count = 0 ; while ( N != 0 ) { if ( ( N & 1 ) == 1 ) { count ++ ; } N = N >> 1 ; } return count ; } static public void Main ( ) { int N = 6 ; Console . Write ( minimumAdditionOperation ( N ) ) ; } }