Friday, March 29, 2013

The shift operators


The shift operators allow programmers to adjust an integer by shifting all of its bits to the left or the right.

The following diagram shows the affect of shifting a value to the left by one digit
  00001111  =  15
SHIFT LEFT
  00011110  =  30


Compound Assignment Operators
The shift operators have equivalents for compound assignment
These are used by adding an equals sign to the operator and using the number of bits to shift by as the operand.


int value = 240;             // 11110000

value >>= 2;      // Result = 60
value <<= 1;      // Result = 120


http://www.blackwasp.co.uk/CSharpShiftOperators.aspx

No comments:

Post a Comment