May 3, 2020

C program using bitwise OR (|)

EX: write a C program to perform OR operation of two intiger's. How to write a C program to perform OR operation of two intiger's. C program to perform OR operation of two intiger's.

Input from user:

a=4 , b=11;

Expected Output:

After performing OR operation the output is: 15





Logic to perform OR operation of two intiger's:

 Firstly you need to know how work OR operator.


  •   The result of OR is 1 if any of the two bits is 1. Otherwise result is 0. 

1. We take two intiger numbers a=4 and b=11.

 2. Binary representation of a OR b is-


      a      = 0000 0100

      b      = 0000 1011
------------------------------------
      a|b   = 0000 1111 =15

3. After performing OR operation 8 bit binary representation is 0000 1111 which is 15 in decimal.


4. So output of the program is  15.




Program:


#include<stdio.h>

void main()
{
int a=4,b=11;

printf("After performing OR operation Output is %d",a|b);

}

Above program shows the following output:


No comments:

Post a Comment

If you have any doubts, please discuss here...