Answered by:
Shift << operator cannot be applied to uint

int z = (1 << 3);
uint p = (1u << 3u);The fist line works but the second line generates this error
"Operator '<<' cannot be applied to operands of type 'uint' and 'uint'"
How could the shift operator not be applied to unsigned integers, that doesn't make sense?
Question
Answers

Check out section 14.8 of the C# Language Specification where it states:
"The predefined shift operators are listed below.
• Shift left:
int operator <<(int x, int count);
uint operator <<(uint x, int count);
long operator <<(long x, int count);
ulong operator <<(ulong x, int count);The << operator shifts x left by a number of bits computed as described below.
The highorder bits outside the range of the result type of x are discarded, the remaining bits are shifted
left, and the loworder empty bit positions are set to zero.
• Shift right:
int operator >>(int x, int count);
uint operator >>(uint x, int count);
long operator >>(long x, int count);
ulong operator >>(ulong x, int count);The >> operator shifts x right by a number of bits computed as described below.
When x is of type int or long, the loworder bits of x are discarded, the remaining bits are shifted
right, and the highorder empty bit positions are set to zero if x is nonnegative and set to one if x is
negative.
When x is of type uint or ulong, the loworder bits of x are discarded, the remaining bits are shifted
right, and the highorder empty bit positions are set to zero."The problem is that your second argument should always be an int.
ShaneB
 Edited by Shane_B Saturday, September 25, 2010 4:03 PM formatting
 Marked as answer by Mattastica Saturday, September 25, 2010 4:09 PM
All replies

Check out section 14.8 of the C# Language Specification where it states:
"The predefined shift operators are listed below.
• Shift left:
int operator <<(int x, int count);
uint operator <<(uint x, int count);
long operator <<(long x, int count);
ulong operator <<(ulong x, int count);The << operator shifts x left by a number of bits computed as described below.
The highorder bits outside the range of the result type of x are discarded, the remaining bits are shifted
left, and the loworder empty bit positions are set to zero.
• Shift right:
int operator >>(int x, int count);
uint operator >>(uint x, int count);
long operator >>(long x, int count);
ulong operator >>(ulong x, int count);The >> operator shifts x right by a number of bits computed as described below.
When x is of type int or long, the loworder bits of x are discarded, the remaining bits are shifted
right, and the highorder empty bit positions are set to zero if x is nonnegative and set to one if x is
negative.
When x is of type uint or ulong, the loworder bits of x are discarded, the remaining bits are shifted
right, and the highorder empty bit positions are set to zero."The problem is that your second argument should always be an int.
ShaneB
 Edited by Shane_B Saturday, September 25, 2010 4:03 PM formatting
 Marked as answer by Mattastica Saturday, September 25, 2010 4:09 PM
