How to find whether binary representation of a number is palindrome in Node.js

1 Answer

0 votes
function is_binary_representation_of_number_palindrome(num) {
    let binary = num.toString(2);
    console.log(binary);

    return binary == [...binary].reverse().join('');
}
        
const num = 153;

if (is_binary_representation_of_number_palindrome(num)) {
    console.log("Palindrome");
} else {
    console.log("Not Palindrome");
}



    
/*
run:
    
10011001
Palindrome
    
*/

 



answered Jan 7, 2024 by avibootz
...