Count number of steps to cover a distance if steps can be taken in powers of 2 | C # program to count minimum number of steps ; Function to count the minimum number of steps ; count the number of set bits in a number ; Driver Code
using System ; class GFG { static int getMinSteps ( int K ) { return countSetBits ( K ) ; } static int countSetBits ( int x ) { int setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } public static void Main ( String [ ] args ) { int n = 343 ; Console . WriteLine ( getMinSteps ( n ) ) ; } }