Bitwise right shift operators in C#


Bitwise operator works on bits and performs bit by bit operation. In Bitwise right shift operator the value of the left operand is moved right by the number of bits specified by the right operand.

In the below code, we have the value −

60 i.e. 0011 1100

On the right shift %minus;

c = a >> 2;

It converts into 15 after right shift twice −

15 i.e. 0000 1111

Example

You can try to run the following code to implement Bitwise right shift operator in C# −

using System;
using System.Collections.Generic;
using System.Text;
namespace Demo {
   class toBinary {
      static void Main(string[] args) {
         int a = 60;    /* 60 = 0011 1100 */
         int b = 0;
         c = a >> 2;    /* 15 = 0000 1111 */
         Console.WriteLine("Value of b is {0}", b);
         Console.ReadLine();
      }
   }
}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

520 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements