Check if number is palindrome or not in base B | Function to check if N in base B is palindrome or not ; Stores the reverse of N ; Stores the value of N ; Extract all the digits of N ; Generate its reverse ; Driver Code
function checkPalindromeB ( N , B ) { var rev = 0 ; var N1 = N ; while ( N1 ) { rev = rev * B + N1 % B ; N1 = parseInt ( N1 / B ) ; } return N == rev ; } var N = 5 , B = 2 ; if ( checkPalindromeB ( N , B ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }