C# equality to Java >>> operator

  • Thread starter Thread starter Dennis Myrén
  • Start date Start date
I think >>> was added to Java as a bit of a hack because they didn't
have any unsigned numbers. C# does support unsigned numbers like uint.
So if your intent is to shift right without extending sign bit. use uint
or ulong data types.

Hope this helps
Leon Lambert
 
Dennis,

From the java language specification, it says:

The value of n>>>s is n right-shifted s bit positions with zero-extension.
If n is positive, then the result is the same as that of n>>s; if n is
negative, the result is equal to that of the expression (n>>s)+(2<<~s) if
the type of the left-hand operand is int

So, if you have an integer in a variable n, you can do this:

// First, shift over two bits.
int pintResult = n >> s;

// Now, if it is negative, perform an additional operation.
if (pintResult < 0)
// Modify.
pintResult += (2 << ~s);

Hope this helps.
 
Back
Top