O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Shift Operators

Much less commonly used than arithmetic operators are the operators that are tightly bound to the underlying bit representation of integral types. One such category consists of shift operators >> and <<, respectively known as left shift and right shift. Shift operators are defined for the int, uint, long, and ulong types but can also be used with other integral types because of implicit conversions.

The following are examples of shift operations:

int left = 3;int lres = left << 5; // 96int right = 42;int rres = right >> 3; // 5

Both operators take two operands. The one on the left takes the expression that needs to be shifted, and the one on the right specifies the number of bits to shift (specified as an int). The operation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required