
.NET 1.1+C# Bitwise Shift Operators (2)
The tenth part of the C# Fundamentals tutorial continues consideration of the C# bitwise operators by introducing the shift functions. These operators extend C#'s capabilities for processing binary information.
Compound Assignment Operators
The shift operators have equivalents for compound assignment similar to other operators discussed in this tutorial. These are used by adding an equals sign to the operator and using the number of bits to shift by as the operand. The following example demonstrates their use:
int value = 240;
value >>= 2; // Result = 60
value <<= 1; // Result = 120
Operator Precedence
We can now extend the operator precedence table with the shift operators.
| Parentheses Operator |
|---|
| () |
| Increment / Decrement Operators |
|---|
| ++(postfix) --(postfix) ++(prefix) --(prefix) |
| Complement Operators |
|---|
| ! ~ |
| Basic Arithmetic Operators |
|---|
| * / % + - |
| Bitwise Shift Operators |
|---|
| << >> |
| Equivalence Operators |
|---|
| == != |
| Logic / Bitwise Operators |
|---|
| & ^ | && || |
| Assignment Operator |
|---|
| = |
| Compound Assignment Operators |
|---|
| *= /= %= += -= >>= <<= &= ^= |= |
14 September 2006