Q:

C# program to demonstrate the example of the right shift operator

belongs to collection: C# Basic Programs | basics

0

C# program to demonstrate the example of the right shift operator

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the right shift operations with different values in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to demonstrate the 
//example of right shift operator in C#.

using System;

class RightShiftDemo
{
    public static void Main()
    {
        int X = 128;
        int Y = 256;

        int R = 0;

        R = X >> 2;
        Console.WriteLine("X>>2 = " + R);

        R = Y >> 3;
        Console.WriteLine("Y>>3 = " + R);
    }
}

Output:

X>>2 = 32
Y>>3 = 32
Press any key to continue . . .

Explanation:

In the above program, we created a RightShiftDemo class that contains the Main() method, here we created three integer variables XY, and R initialized with 128, 256, and 0.

Now calculate the statements.

R = X >> 2;
R  =  128 / Power(2,2);
R  =  128 /( 2*2);
R  =  128/4;
R  = 32; 

Then,

R = Y >> 3;
R = 256 >> 3;
R = 256/ Power(2,3);
R = 256/(2*2*2);
R = 256/8;
R = 32;

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to find the division of exponents of th... >>
<< C# program to calculate the size of the area in sq...