Bit OR operator - C Operator

C examples for Operator:Bit Operator

Introduction

The bitwise OR operator, |, results in 1 if either or both of the corresponding bits are 1; otherwise, the result is 0.

If you combine the same values of x and y using the | operator in a statement such as this:

Demo Code

#include <stdio.h> 

int main(void) { 
    /*w  ww  . j  a va 2  s .  co  m*/
    int x = 13;
    int y = 6;
    int z = x | y;                // OR the bits of x and y
    
    printf("%d",z);
    return 0; 
} 

Result

the result would be as follows:

x           0       0       0      0       1       1        0       1
y           0       0       0      0       0       1        1       0
x | y       0       0       0      0       1       1        1       1

The value stored in z would therefore be 15 (binary 1111).


Related Tutorials