mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2025-12-06 15:34:06 +00:00
18 lines
357 B
C++
18 lines
357 B
C++
#include "soln.hpp"
|
|
|
|
uint32_t Solution::reverseBits(uint32_t n)
|
|
{
|
|
uint32_t result = 0;
|
|
for (int i = 0; i < 32; i++)
|
|
{
|
|
result = result << 1; // increase result size
|
|
result += (n & 1); // append last bit
|
|
n = n >> 1; // move to next bit
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool Solution::test(uint32_t n, uint32_t answer)
|
|
{
|
|
return reverseBits(n) == answer;
|
|
} |