Link to home
Start Free TrialLog in
Avatar of williamcampbell
williamcampbellFlag for United States of America

asked on

bitwise unsigned right shift operator


  Whats the C# equivalent of >>> ?
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

ASKER

>>> from Flash ActionScript / JScript
Avatar of Carl Tawn
The right shift operator in C# is >>.

Theres a more complete overview of binary operators here:

    http://www.c-sharpcorner.com/Language/BitWiserOpsInCSCH001.asp
The problem is C#'s >> right shifts but does not preserve the sign ...

  so if the number is negative it shifts a zero in making the number positive

  0111  7  
  >> 1
  0011  3

  1111  -7
  >> 1
  0111  3  (not -3)

  In Java  >>>
  1111 -7
  >>> 1
  1011 -3

  Hope this clears up what I want


My bad I got it the wrong way around

  C# >> does preserve the sign bit

  Java >>> clears the sign bit

  Any bit pushers out there give me some C# code that does >>>?

Thanks
Avatar of c_myers
c_myers

You can cast/convert the int's to uint's and then >> and << will be unsigned (zero-fill).

If you use int or long, >> will be signed.

If you use uint or ulong, >> will be unsigned.

The reason Javascript/JScript/JScript.NET has >>> is because it's not strongly typed, and therefore there is no difference between signed and unsigned integer, thus they need an explicit operator for unsigned bitwise operations.
FYI, the first paragraph in this article talks about what I just said. Perhaps they can explain it better than I :) ---

http://www.ondotnet.com/pub/a/dotnet/2001/06/07/csharp_java.html?page=3

 Ack I still dont get it

 perhaps a better question is

 function bit_rol(num,cnt)
{
    return (num << cnt) | (num >>> (32-cnt) );
}

Conver this to C#

 public Int32 bit_rol(Int32 num,Int32 cnt)
{
   ???
}
ASKER CERTIFIED SOLUTION
Avatar of c_myers
c_myers

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice one C_m thanks a bunch.