What is the equivalent (in C#) of Java's >>> operator? Just to clarify, I'm not referring to the >> and << operators.
+7
A:
In C#, you can use unsigned integer types, and then the <<
and >>
do what you expect. The MSDN documentation on shift operators gives you the details.
Since Java doesn't support unsigned integers (apart from char
), this additional operator became necessary.
Lucero
2009-12-10 10:52:12
great thanks for the input
Nikolaos
2009-12-10 11:20:05
+2
A:
Java doesn't have an unsigned left shift (<<<
), but either way, you can just cast to uint
and shfit from there.
E.g.
(int)((uint)foo >> 2); // temporarily cast to uint, shift, then cast back to int
Matt
2009-12-10 10:54:57
C# doesn't have any 'unsigned shift' operators. Java has an unsigned RIGHT shift, but not an unsigned LEFT shift.
Matt
2009-12-10 11:08:05
+1 Thanks for your input on this. Will keep it in mind for when I am forced to use signed types.
Nikolaos
2009-12-10 11:21:06
There's no need for <<< because sign-extension isn't relevant for left shifts.
dan04
2010-03-24 06:12:12