Bitwise Algorithms

‘Recent Articles’ on Bit Magic
Topic :

Basic :

  1. Find the element that appears once
  2. Detect if two integers have opposite signs
  3. Add 1 to a given number
  4. Multiply a given Integer with 3.5
  5. Turn off the rightmost set bit
  6. Find whether a given number is a power of 4 or not
  7. Compute modulus division by a power-of-2-number
  8. Rotate bits of a number
  9. Find the Number Occurring Odd Number of Times
  10. Check for Integer Overflow
  11. Little and Big Endian Mystery
  12. Count set bits in an integer
  13. Count number of bits to be flipped to convert A to B
  14. Efficient way to multiply with 7
  15. Program to find whether a no is power of two
  16. Position of rightmost set bit
  17. Binary representation of a given number
  18. Find position of the only set bit
  19. How to swap two numbers without using a temporary variable?
  20. Swap two nibbles in a byte
  21. How to turn off a particular bit in a number?
  22. Russian Peasant (Multiply two numbers using bitwise operators)
  23. Add two bit strings
  24. Write your own strcmp that ignores cases
  25. Check if two numbers are equal without using arithmetic and comparison operators
  26. Find XOR of two number without using XOR operator
  27. XOR counts of 0s and 1s in binary representation
  28. Calculate XOR from 1 to n
  29. Multiply a number with 10 without using multiplication operator
  30. Equal Sum and XOR
  31. Swap three variables without using temporary variable
  32. Check if a number has bits in alternate pattern
  33. Count minimum bits to flip such that XOR of A and B equal to C
  34. Efficient method for 2’s complement of a binary string
  35. Toggle case of a string using Bitwise operators
  36. Toggling k-th bit of a number
  37. Convert decimal fraction to binary number
  38. Toggle all the bits of a number except k-th bit
  39. Set the rightmost unset bit
  40. Convert a binary number to octal
  41. Check in binary array the number represented by a subarray is odd or even
  42. Toggle the last m bits
  43. 1 to n bit numbers with no consecutive 1s in binary representation
  44. Toggle bits in the given range
  45. Unset bits in the given range
  46. Find the largest number with n set and m unset bits
  47. Find the smallest number with n set and m unset bits
  48. Sum of numbers with exactly 2 bits set
  49. Check if binary representation of a given number and its complement are anagram
  50. Josephus Problem Using Bit Magic

Intermediate :

  1. Swap bits in a given number
  2. Add two numbers without using arithmetic operators
  3. Smallest of three integers without comparison operators
  4. A Boolean Array Puzzle
  5. Compute the integer absolute value (abs) without branching
  6. Compute the minimum or maximum of two integers without branching
  7. Find the two non-repeating elements in an array of repeating elements
  8. Write an Efficient C Program to Reverse Bits of a Number
  9. Smallest power of 2 greater than or equal to n
  10. Write an Efficient Method to Check if a Number is Multiple of 3
  11. Write a C program to find the parity of an unsigned integer
  12. Swap all odd and even bits
  13. Check if a number is multiple of 9 using bitwise operators
  14. Check if binary representation of a number is palindrome
  15. Generate n-bit Gray Codes
  16. Check if a given number is sparse or not
  17. Euclid’s Algorithm when % and / operations are costly
  18. Find nth Magic Number
  19. How to swap two bits in a given integer?
  20. Calculate 7n/8 without using division and multiplication operators
  21. Calculate square of a number without using *, / and pow()
  22. Generate 0 and 1 with 25% and 75% probability
  23. Find even occurring elements in an array of limited range
  24. Cyclic Redundancy Check and Modulo-2 Division
  25. Copy set bits in a range
  26. Check if a number is Bleak
  27. Count strings with consecutive 1’s
  28. Gray to Binary and Binary to Gray conversion
  29. Find Next Sparse Number
  30. Sum of bit differences among all pairs
  31. Sum of Bitwise And of all pairs in a given array
  32. Bitwise and (or &) of a range
  33. Multiples of 4 (An Interesting Method)
  34. Length of the Longest Consecutive 1s in Binary Representation
  35. Pairs of complete strings in two sets of strings
  36. Find profession in a special family
  37. Print first n numbers with exactly two set bits
  38. Check if bits of a number has count of consecutive set bits in increasing order
  39. Subset sum queries using bitset
  40. Maximum 0’s between two immediate 1’s in binary representation
  41. Count all pairs of an array which differ in K bits
  42. Efficiently check if a string has duplicates without using any additional data structure
  43. Count trailing zero bits using lookup table
  44. Count smaller numbers whose XOR with n produces greater value
  45. Check divisibility in a binary stream
  46. Multiplication of two numbers with shift operator
  47. Determine if a string has all Unique Characters
  48. Reverse an array without using subtract sign ‘-‘ anywhere in the code
  49. Count numbers whose sum with x is equal to XOR with x
  50. Maximum XOR value of a pair from a range
  51. Numbers whose bitwise OR and sum with N are equal
  52. Change bits to make specific OR value
  53. Count smaller values whose XOR with x is greater than x
  54. Next greater integer having one more number of set bits
  55. Check if two numbers are bit rotations of each other or not
  56. Previous smaller integer having one less number of set bits
  57. Check if binary representations of two numbers are anagram
  58. Maximize a given unsigned number number by swapping bits at it’s extreme positions
  59. Set bits in N equals to M in the given range

Hard :

Misc :

Quick Links :

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Company Wise Coding Practice    Topic Wise Coding Practice