3. Reverse Bits

Question : Write a program that takes a 64-bit word, output the reverse of that word. I would urge you to minimize the window and try to solve this question on your own first.   Method - 1 Brute Force Solution Simply apply the bitswap method we used earlier on all the extreme bits. Time … Continue reading 3. Reverse Bits

Advertisements

2. Swap bits

Question : Given a number and 2 indices return the number after swapping bits present at those indices. Method-1 : Brute-Force We can swap bits by following the given steps :- 1. Using bitmasks to extract the ith and jth┬ábits. 2. Save the extracted bits to some local variables. 3. Write the jth ┬ábit to … Continue reading 2. Swap bits