Challenge 42

🌌

42

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

In pop culture, the number 42 is infamous after being popularised by the Hitchhiker's Guide to the Galaxy, in which it's jokingly referred to as the answer to the "ultimate question of life, the universe and everything"

The number 42 also has some interesting mathematical properties:

For this task, let's focus on binary palindromes - create a function that takes an input denary number and outputs whether its two's complement binary representation is a palindrome

Examples:

isBinaryPalindrome(42) returns true

isBinaryPalindrome(6) returns true

isBinaryPalindrome(-7) returns true

isBinaryPalindrome(-6) returns false

Extension:

Output all the binary palindromes in the range -1024 to 1023

Solutions

IGCSE 0478 / O-Level 2210 A-Level 9618