stdbit


1. Bitwise AND Operation

#include <stdio.h>

int main() {
  int a = 10;  // 1010 in binary
  int b = 5;   // 0101 in binary

  printf("%d & %d = %d\n", a, b, a & b);  // Output: 1010 & 0101 = 0100 (4)
  return 0;
}

2. Bitwise OR Operation

#include <stdio.h>

int main() {
  int a = 10;  // 1010 in binary
  int b = 5;   // 0101 in binary

  printf("%d | %d = %d\n", a, b, a | b);  // Output: 1010 | 0101 = 1111 (15)
  return 0;
}

3. Bitwise XOR Operation

4. Bitwise NOT Operation

5. Checking Least Significant Bit

6. Setting Least Significant Bit

7. Clearing Least Significant Bit

8. Toggling Least Significant Bit

9. Checking Most Significant Bit

10. Setting Most Significant Bit

11. Clearing Most Significant Bit

12. Toggling Most Significant Bit

13. Checking Specific Bit

14. Setting Specific Bit

15. Clearing Specific Bit

16. Toggling Specific Bit

17. Getting Bit Count

18. Setting All Bits

19. Clearing All Bits

20. Rolling Left

21. Rolling Right

22. Getting Sign of Integer

23. Getting Absolute Value of Integer

24. Finding Integer Minimum and Maximum

25. Finding 2's Complement

26. Finding 1's Complement

27. Finding Bitwise Swapped Value

28. Finding Reverse Bits

29. Swapping Two Integers Using Bit Manipulation

30. Finding Divisor

31. Finding Remainder

32. Calculating GCD Using Bit Manipulation

33. Calculating LCM Using Bit Manipulation

34. Checking If a Number is a Power of 2

35. Finding the Next Power of 2

36. Finding the Previous Power of 2

37. Finding the Number of Ones in a Binary Representation

38. Finding the Number of Zeros in a Binary Representation

39. Reversing Bits in a Byte

40. Reversing Bits in a Word

41. Finding the Parity of a Word

42. Detecting Sign of a Floating Point Number

43. Fast Multiplication Using Bit Manipulation

44. Fast Exponentiation Using Bit Manipulation

45. Finding the Square Root of a Number Using Bit Manipulation

46. Finding the Logarithm Base 2 Using Bit Manipulation

47. Checking If a String is a Palindrome Using Bit Manipulation

48. Finding the Number of Distinct Elements in an Array Using Bit Manipulation

49. Finding the Majority Element in an Array Using Bit Manipulation

50. Finding the Union and Intersection of Two Sets Using Bit Manipulation