Categories
algorithms kotlin

Problem 5.2 from EPI -> Swap bits

The problem 5.2 is quite simple, it asks for bit swapping, so we need to check if i-th or j-th bit are different, if not no need to swap, if they are then just xor the number with 1 shifted left by i bits and 1 shifted left by j bits. Take a look at the code here.

Leave a Reply

Your email address will not be published. Required fields are marked *