C# equality to Java >>> operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis Myrén

    #1

    C# equality to Java >>> operator


    Hi.
    Is there a C# operator that is equal to the java operator:[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Regards
    Dennis

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Leon Lambert

    #2
    Re: C# equality to Java >>> operator

    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 Myrén wrote:[color=blue]
    > Hi.
    > Is there a C# operator that is equal to the java operator:
    >
    >
    > Regards
    > Dennis
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: C# equality to Java >>> operator

      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.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - nicholas.paldin o@exisconsultin g.com

      "Dennis Myrén" <dennis.myren@g reydigital.no> wrote in message
      news:OhOr%23usd DHA.2112@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      >
      > Hi.
      > Is there a C# operator that is equal to the java operator:[color=green][color=darkred]
      > >>>[/color][/color]
      >
      > Regards
      > Dennis
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it![/color]


      Comment

      Working...