How to check if the binary representation of a number is a palindrome in PHP

1 Answer

0 votes
function isPalindrome($n) {
    return decbin($n) == strrev(decbin($n));
}
        
$n = 27;

echo decbin($n) . "\n";

echo ((isPalindrome($n) ? "Yes" : "No"));





/*
run:

11011
Yes

*/

 



answered Jul 15, 2022 by avibootz
...