Algorithm Algorithm Gist
Counting number of set bits Counting set bits using bitset.
Counting set bits using __builtin_popcount
Swapping integers using XOR operation XOR stands for exclusive or. XOR opertion of two bits results in 1 only if the bits are different; for the same bits XOR operation results in 0.
Converting a binary string into its equivalent decimal number Starting with the least significant (rightmost) bit we multiple each binary digit with the power of 2 starting with 0. As we move towards the most significant (leftmost) bit we increase the power of 2 by 1. The resultant decimal number is the addition of all the multiplications.
Example : Binary string (0110)
resultant decimal = 0 . 2^3 + 1 . 2^2 + 1 . 2^1 + 0 . 2^0
resultant decimal = 6

Copyright (c) 2019-2020,
All rights reserved.