Bitwise Operator Bits पर काम करता है और Bit-by-Bit Operation Perform करता है।
निम्न Bitwise Operators हैं:
| Operator | Description | Example |
|---|---|---|
| & | Binary AND Operator Result में Bit को Copy करता है यदि वह दोनों Operands में Exist करता है। | (A & B) = 12, जो 0000 1100 है |
| | | Binary OR Operator Bit को Copy करता है यदि वह किसी एक Operand में Exist करता है। | (A | B) = 61, जो 0011 1101 है |
| ^ | Binary XOR Operator Bit को Copy करता है यदि वह एक Operand में Set है लेकिन दोनों में नहीं। | (A ^ B) = 49, जो 0011 0001 है |
| ~ | Binary Ones Complement Operator Unary है और Bits को 'Flip' करने का Effect डालता है। | (~A) = 61, जो 2's Complement के कारण 1100 0011 है। |
| << | Binary Left Shift Operator. Left Operand की Value को Right Operand द्वारा Specified Bits की संख्या से Left Move करता है। | A << 2 = 240, जो 1111 0000 है |
| >> | Binary Right Shift Operator. Left Operand की Value को Right Operand द्वारा Specified Bits की संख्या से Right Move करता है। | A >> 2 = 15, जो 0000 1111 है |
निम्न Example दर्शाता है कि C# में Bitwise Operators के साथ कैसे काम करें।
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int a = 60; /* 60 = 0011 1100 */ int b = 13; /* 13 = 0000 1101 */ int c = 0; c = a & b; /* 12 = 0000 1100 */ Console.WriteLine("Value of c is {0}", c); c = a | b; /* 61 = 0011 1101 */ Console.WriteLine("Value of c is {0}", c); c = a ^ b; /* 49 = 0011 0001 */ Console.WriteLine("Value of c is {0}", c); c = ~a; /*-61 = 1100 0011 */ Console.WriteLine("Value of c is {0}", c); c = a << 2; /* 240 = 1111 0000 */ Console.WriteLine("Value of c is {0}", c); c = a >> 2; /* 15 = 0000 1111 */ Console.WriteLine("Value of c is {0}", c); Console.ReadLine(); } } }Output
Value of c is 12 Value of c is 61 Value of c is 49 Value of c is -61 Value of c is 240 Value of c is 15