- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use RightShift Operators in C#?
The left operands value is moved right by the number of bits specified by the right operand in Right Shift Operator.
Let us see an example of Right Shift operator in C# −
using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { int a = 60; /* 60 = 0011 1100 */ int b = 0; b = a >> 2; /* 15 = 0000 1111 */ Console.WriteLine("Right Shift Operator - Value of b is {0}", b); Console.ReadLine(); } } }
Above, the value of a is 60 i.e. 0011 1100 in binary.
Set right shift operator as shown in the above example. This shifts the bits to the right twice −
a >> 2
Now the output will be 15 i.e.
15 = 0000 1111
Advertisements