views:

378

answers:

2

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
great thanks for the input
Nikolaos
+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
Java doesn't? or C# doesn't?
Will
C# doesn't have any 'unsigned shift' operators. Java has an unsigned RIGHT shift, but not an unsigned LEFT shift.
Matt
+1 Thanks for your input on this. Will keep it in mind for when I am forced to use signed types.
Nikolaos
There's no need for <<< because sign-extension isn't relevant for left shifts.
dan04