A legacy protocol transmits register fields of a configurable width b bits. Due to a wiring quirk on the receiving hardware, every field must be bit-mirrored (its bits reversed left-to-right) before use.
Given the field width b and a value n known to fit in b bits, write n as a b-bit binary string (padded with leading zeros to exactly b digits), reverse that string, and print the decimal value of the reversed string.
Line 1: an integer b, the field width in bits.
Line 2: an integer n.
A single integer: the decimal value obtained by reversing the b-bit binary representation of n.
Example 1
Input
4 3
Expected
12
Explanation
3 in 4 bits is 0011; reversing the bits gives 1100, which is 12.
Example 2
Input
8 1
Expected
128
Explanation
1 in 8 bits is 00000001; reversing gives 10000000, which is 128.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →