Jon Jagger
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 14 Expressionsprevious at this levelnext at this level 14.8 Shift operators Paragraph 11 The << and >> operators are used to perform bit shifting operations. shift-expression : additive-expression shift-expression << additive-expression shift-expression >> additive-expression Paragraph 21 For an operation of the form x << count or x >> count, binary operator overload resolution (§14.2.4) is applied to select a specific operator implementation. 2 The operands are converted to the parameter types of the selected operator, and the type of the result is the return type of the operator. Paragraph 31 When declaring an overloaded shift operator, the type of the first operand must always be the class or struct containing the operator declaration, and the type of the second operand must always be int. Paragraph 41 The predefined shift operators are listed below. Paragraph 51 For the predefined operators, the number of bits to shift is computed as follows: Paragraph 61 If the resulting shift count is zero, the shift operators simply return the value of x. Paragraph 71 Shift operations never cause overflows and produce the same results in checked and unchecked contexts. Paragraph 81 When the left operand of the >> operator is of a signed integral type, the operator performs an arithmetic shift right wherein the value of the most significant bit (the sign bit) of the operand is propagated to the high-order empty bit positions. 2 When the left operand of the >> operator is of an unsigned integral type, the operator performs a logical shift right wherein high-order empty bit positions are always set to zero. 3 To perform the opposite operation of that inferred from the operand type, explicit casts can be used. 4 For example, if x is a variable of type int, the operation unchecked((int)((uint)x >> y)) performs a logical shift right of x.
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS