C solved programs/examples on Bitwise Operators

This section contains solved programs on Bitwise Operators with output and explanation, here we will learn how and why to use bitwise operators by demonstrating relevant examples.

The operators which we are going to use in these examples are bitwise AND (&), bitwise OR (|), Left shift operator (<<), right shift operator (>>) and more.

List of bitwise operator example programs in C

Here is the list of some of the C language programs based on Bitwise operators.

  1. C program to find Binary number of a Decimal number.
    In this C program, we will read an integer (decimal) number and print its Binary values (Binary number).
  2. C program to get minimum number of bits to store an integer number.
    In this C program, we will find how many minimum bit(s) are required to store an integer number?
  3. C program to swap two bits.
    Swapping of two bits of a byte using C program: Here, we will learn how to swap two bits of a byte?
  4. C program to check whether all bits of a number are UNSET/LOW?
    Learn: how we can check that whether all bits of a one byte (8 bits) number are UNSET/LOW using C program? Here, we are implemented the program for this using Bitwise AND (&) operator.
  5. C program to swap bytes (for example convert 0x1234 to 0x3412).
    Here, we have a number of two byte (short integer) in hexadecimal format and we are going to swap its bytes using C program.
  6. C program to reverse bits of a number.
    In this C program, we are going to learn how to reverse bits of a number? Here, we have a number and printing its bits value in reverse order.
  7. C program to count number of 1's in a number.
    In this C program, we are going to learn how to count set bits in a number? Here, we have a number and print total number of 1’s of a number.
  8. C program to swap nibbles of a byte/word.
    Here, we have a number of one byte in hexadecimal format and we are writing a program to swap its nibbles.
  9. C program to demonstrate left shift (<<) operator.
    In this C program, we are going to learn how to use bitwise left shift operator? Here is an example, demonstrating the use of left shift bitwise operator.
  10. C program to demonstrate right shift (>>) operator.
    In this C program, we are going to learn how to use bitwise right shift operator? Here is an example, demonstrating the use of right shift bitwise operator.
  11. C program to set/clear (low/high) bits of a number.
    In this C program, we are going to learn how to set (make all bits high) and clear (make all bits low) all bits of a number.
  12. C program to swap two numbers using bitwise operator.
    In this C program, we are going to learn how to swap two integer numbers using bitwise operator? Here we are swapping numbers without using any third variable.
  13. C program to Count the Number of Trailing Zeroes in an Integer.
    Count the number of trailing zeroes in an integer in C: Here, we are going to see how to use bitwise operators for counting number of trailing zeros in the binary representation of an integer?
  14. C program to find the Highest Bit Set for any given Integer.
    Find the highest bit set of a number in C: Here, we are going to see how to use bitwise operators tofind the highest bit set in the binary representation of given integer?
  15. C program to check if all the bits of a given integer is one (1).
    Check if all the bits of a given integer is one (1) using C program: Here, we are going to implement a C program that will check whether all bits of an integer is set/one (1) or not.
  16. C program to count number of bits set to 1 in an Integer.
    Count number of bit set to 1 in an integer using C program: Here, we are going to implement a C program that will count the total set bits (bits which are set to 1) in an integer number using bitwise operator.
  17. C program to check whether a given number is palindrome or not using Bitwise Operator.
    Palindrome number check program in C: In this article, we are going to see how to use bitwise operators to find whether a number (binary representation) is palindrome or not?
  18. C program to find odd or even number using bitmasking.
    In this article, we are going to see how to check a number odd or even using bitwise operators?
  19. C program to replace bit in an integer at a specified position from another integer.
    In this article, we are going to learn how to replace a bit of a number at a specified position from another number?
  20. C program to swap two Integers using Bitwise Operators.
    In this article, we are going to see how to swap two no using bitwise operator without using any temporary operators?
  21. C program to Check if nth Bit in a 32-bit Integer is set or not.
    In this article, we are going to see how to find nth bit of a 32-bit integer is set or not using bitwise operator?
  22. C program to check a number contain the alternative pattern of bits
    Read an integer number from the user, then check given number contains an alternate bit pattern or not using C program.
  23. C program to find the next number power of 2
    Read an integer number from the user, then find the next number power of 2 using the bitwise right shift operator using C program.
  24. C program to find the position of MSB bit of an unsigned integer number
    Read an integer number from the user, then find the position of MSB of an unsigned integer number using C program.
  25. C program to round off an integer number to the next lower multiple of 2
    Read an integer number from the user, and then we will round off the input number to the next lower multiple of 2 using C program.
  26. C program to print the range of fundamental data types using bitwise operators
    Here, we will create two user-defined functions to print the range of signed and unsigned data types.
  27. C program to count the number of leading zeros in a binary number
    Read an integer number from the user, find the leading zeros in the input binary number using C program.
  28. C program to read a byte and print bits between given positions
    Read an 8-bit binary number as a string, then print the bits between given positions using C program.
  29. C program to swap two bits of a 32-bit integer number
    Read an integer number and bit positions. Then swap bit positions of a given number using C program.
  30. C program to check a given number is the power of 2 using bitwise operator
    Read an integer number, and check whether the input number is a power of 2 or not using bitwise operator.
  31. C program to count the number of bits to be flipped to convert a number to another number
    Read two integer numbers, then count the number of bits that need to be flipped to convert a number to another number using C program.
  32. C program to print bits that need to be flipped to convert a number to another number
    Read two integer numbers, and then print the bits that need to be flipped to convert a number to another number.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.