Find the possible permutation of the bits of N | C # implementation of the above approach ; Function that returns true if it is possible to arrange the bits of n in alternate fashion ; To store the count of 1 s in the binary representation of n ; If the number set bits and the number of unset bits is equal ; Driver code
using System ; class GFG { static int TOTAL_BITS = 32 ; static int CountBits ( int value ) { int count = 0 ; while ( value != 0 ) { count ++ ; value &= value - 1 ; } return count ; } static bool isPossible ( int n ) { int cnt = CountBits ( n ) ; if ( cnt == TOTAL_BITS / 2 ) return true ; return false ; } public static void Main ( String [ ] arr ) { int n = 524280 ; if ( isPossible ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }