Evil Number | Returns number of 1 s from the binary number ; Counting 1 s ; Check if number is evil or not ; Converting n to binary form ; Calculating remainder ; Storing the remainders in binary form as a number ; Calling the count_one function to count and return number of 1 s in bin ; Driver code
function count_one ( n ) { let c_one = 0 ; while ( n != 0 ) { let rem = n % 10 ; if ( rem == 1 ) c_one = c_one + 1 ; n = parseInt ( n / 10 , 10 ) ; } return c_one ; } function checkEvil ( n ) { let i = 0 , bin = 0 , n_one = 0 ; while ( n != 0 ) { let r = n % 2 ; bin = bin + r * ( Math . pow ( 10 , i ) ) ; n = parseInt ( n / 2 , 10 ) ; } n_one = count_one ( bin ) ; if ( n_one % 2 == 0 ) return 1 ; else return 0 ; } let check , num ; num = 32 ; check = checkEvil ( num ) ; if ( check == 1 ) document . write ( num + " " ) ; else document . write ( num + " " ) ;