Computer Science, asked by sahilshukla279, 1 year ago

Write a program to divide any positive even integer by 2 using bitwise shift operator.

Answers

Answered by AneesKakar
1

Explanation:

C Program for dividing any positive integer by 2 Using Bitwise Right -Shift Operator(>>)

#include <stdio.h>  

int main()

{

   int x = 20;

   // Use bitwise right shift to divide

   // number by power of 2

   printf("20 / (2^1) => %d\n", (a >> 1));

   printf("20 / (2^2) => %d\n", (a >> 2));

   printf("20/ (2^3) => %d\n", (a >> 3));

   return 0;

}

Output:

20 / (2^1) => 10

20 / (2^2) => 5

20 / (2^3) => 3

Similar questions