Check if a N base number is Even or Odd | To return value of a char . ; Function to convert a number from N base to decimal ; power of base ; Decimal equivalent is str [ len - 1 ] * 1 + str [ len - 1 ] * base + str [ len - 1 ] * ( base ^ 2 ) + ... ; A digit in input number must be less than number 's base ; Returns true if n is even , else odd ; Driver Code
function val ( c ) { if ( c >= ' ' && c <= ' ' ) return c . charCodeAt ( ) - ' ' . charCodeAt ( ) ; else return c . charCodeAt ( ) - ' ' . charCodeAt ( ) + 10 ; } function toDeci ( str , base ) { let len = str . length ; let power = 1 ; let num = 0 ; let i ; for ( i = len - 1 ; i >= 0 ; i -- ) { if ( val ( str [ i ] ) >= base ) { document . write ( " " ) ; return - 1 ; } num += val ( str [ i ] ) * power ; power = power * base ; } return num ; } function isEven ( num , N ) { let deci = toDeci ( num , N ) ; return ( deci % 2 == 0 ) ; } let num = " " ; let N = 16 ; if ( isEven ( num , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }