| Algorithm | Algorithm Gist |
|---|---|
| Counting number of set bits | Counting set bits using bitset. Counting set bits using __builtin_popcount Counting set bits using Logical AND (&) and Right Shift (») operators |
| 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 . 23 + 1 . 22 + 1 . 21 + 0 . 20 resultant decimal = 6 |
© 2019-2026 Algotree.org | All rights reserved.
This content is provided for educational purposes. Feel free to learn, practice, and share knowledge.
For questions or contributions, visit algotree.org
"Without requirements or design, programming is the art of adding bugs to an empty text file. - Louis Srygley"