• Home
  • 3.16 Bitwise OR

3.16 Bitwise OR

View Categories

3.16 Bitwise OR

< 1 min read

Table of Contents

The bitwise OR operator | performs an OR operation on each corresponding bit of two integer operands. A bit in the result is 1 when at least one of the corresponding bits is 1.

#include <stdio.h>

int main()
{
    int a = 12;
    int b = 10;

    printf("a | b = %d\n", a | b);

    return 0;
}

Example Output #

a | b = 14

Explanation #

The values are represented in binary as:

12 = 1100
10 = 1010
     ----
     1110

Each pair of corresponding bits is compared:

a b a | b
0 0 0
0 1 1
1 0 1
1 1 1

Therefore, 1100 | 1010 produces 1110, which is decimal 14.

The bitwise OR operator operates on the individual bits of integer operands.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *