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
< ? php function count_one ( $ n ) { $ c_one = 0 ; while ( $ n != 0 ) { $ rem = $ n % 10 ; if ( $ rem == 1 ) $ c_one = $ c_one + 1 ; $ n = $ n / 10 ; } return $ c_one ; } function checkEvil ( $ n ) { $ i = 0 ; $ bin = 0 ; $ n_one = 0 ; while ( $ n != 0 ) { $ r = $ n % 2 ; $ bin = $ bin + $ r * ( pow ( 10 , $ i ) ) ; $ n = $ n / 2 ; } $ n_one = count_one ( $ bin ) ; if ( $ n_one % 2 == 0 ) return 1 ; else return 0 ; } $ i ; $ check ; $ num ; $ num = 32 ; $ check = checkEvil ( $ num ) ; if ( $ check == 1 ) echo $ num , " ▁ is ▁ Evil ▁ Number STRNEWLINE " ; else echo $ num , " ▁ is ▁ Odious ▁ Number STRNEWLINE " ; ? >