Reverse the 32 bits
Given a whole number n from 0 to 232 - 1, write it in binary as exactly 32 bits, with leading 0s filling the width. Reverse the order of those 32 bits and return the number they make.
Binary is base 2: each digit, called a bit, is 0 or 1 and is worth a power of two, 1, 2, 4, 8 and so on from the right. The leading 0s count: 6 is 110, but as 32 bits it is 29 zeros followed by 110, so its reversal starts with 011 and ends with 29 zeros.
String tools such as format(n, "032b") and int(text, 2) pass the tests. Practice the version that moves bits with &, |, << and >>.
n = 6Output16106127366 is 29 zeros then 110. Reversed, it is 011 then 29 zeros: 230 + 229 = 1073741824 + 536870912.
n = 1Output21474836481 is 31 zeros then a 1. Reversed, the 1 comes first: 231.
n = 4026531840Output154026531840 is 15 × 228: four 1s, then 28 zeros. Reversed, it is 28 zeros, then four 1s, which is 15.
0 ≤ n ≤ 232 - 1
Treat n as exactly 32 bits, leading 0s included.
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.