Thabit number | Utility function to check power of two ; function to check if the given number is Thabit Number ; Add 1 to the number ; Divide the number by 3 ; Check if the given number is power of 2 ; Driver Program ; Check if number is thabit number
function isPowerOfTwo ( n ) { return ( n && ! ( n & ( n - 1 ) ) ) ; } function isThabitNumber ( n ) { n = n + 1 ; if ( n % 3 == 0 ) n = n / 3 ; else return false ; if ( isPowerOfTwo ( n ) ) return true ; else return false ; } var n = 47 ; if ( isThabitNumber ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;