Mid From PDF Coding C# Coding Interview

Reverse the bits of a number?

public uint ReverseBits(uint n) {
uint result = 0;
for (int i = 0; i < 32; i++) {
result <<= 1;
result |= (n & 1);
n >>= 1;
}
return result;
}

Explanation:

Iteratively take least significant bit of n, add it to result’s LSB, shift both accordingly.

Follow on:

Follow on:

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details