codekofi
← All problems

Problem 124

Easy

1 · Worked examples

0 / 3

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 3 outputs correctly.

The accepted solution

1unsigned int solution(unsigned int n) {
2
3 unsigned int ans = 0;
4
5 for (int i = 0; i < 32; i++) {
6 ans = (ans << 1) | (n & 1);
7 n = n >> 1;
8 }
9
10 return ans;
11}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.