Check if number is palindrome or not in Octal | Javascript program to check if octal representation of a number is prime ; Function to Check no is in octal or not ; Function To check no is palindrome or not ; If number is already in octal , we traverse digits using repeated division with 10. Else we traverse digits using repeated division with 8 ; To store individual digits ; Traversing all digits ; checking if octal no is palindrome ; Driver code
const MAX_DIGITS = 20 ; function isOctal ( n ) { while ( n ) { if ( ( n % 10 ) >= 8 ) return false ; else n = Math . floor ( n / 10 ) ; } return true ; } function isPalindrome ( n ) { var divide = ( isOctal ( n ) == false ) ? 8 : 10 ; var octal = new Array ( MAX_DIGITS ) ; var i = 0 ; while ( n != 0 ) { octal [ i ++ ] = n % divide ; n = Math . floor ( n / divide ) ; } for ( var j = i - 1 , k = 0 ; k <= j ; j -- , k ++ ) if ( octal [ j ] != octal [ k ] ) return false ; return true ; } var n = 97 ; if ( isPalindrome ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;