Unsigned Right Shift Operator that in javascript to C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wonderpeng
    New Member
    • Apr 2010
    • 2

    Unsigned Right Shift Operator that in javascript to C#

    Hi,

    I want to call the JavaScript function but no well in the client program, so i did the translation of code from JavaScript to the C#.
    When i was try put in the ">>>" , it was warm me it's wrong.
    And then i try to find the method to deal with, but failed.
    The question is like under:
    JavaScript:
    Code:
          A >>> (B - C)                              ;A: Signed long, and less then zero.
    when i try to with the code like under in C# :
    (1)
    Code:
    (ulong)A >> (B - C);
    (2)
    Code:
    Math.abs(A) >>(B - C);
    the result was different with the JavaScript executed.
    Is there have some to resolve this problem? Help me,please!
    My E-mail: <email snipped>
    And thank you for reading this topic.
    Thanks a lot.
    Last edited by Frinavale; Apr 27 '10, 04:03 PM. Reason: Please do not post your email on this site.
  • wonderpeng
    New Member
    • Apr 2010
    • 2

    #2
    Can anyone give a hand?

    Comment

    • Christian Binder
      Recognized Expert New Member
      • Jan 2008
      • 218

      #3
      Did you assign the value to a variable?
      E.g.
      A = A >> B; //A will be right-shifted B times

      Which types are your variables of (A, B, C)?
      Which values did you test, what did you expect and which results did you get?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        What does the javascript function looklike and do?
        I can find no reference to a triple bracket operator like <<< or >>>

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          I don't understand whether you want to do the shift in JavaScript or in C#.
          Link to JavaScript bitwise documentation: MDC: Bitwise Operators.

          There is a difference between:
          (ulong)A >> (B - C);

          and

          Math.abs(A) >>(B - C);


          See how you're using the Math.abs function?
          Why...I don't understand what you're doing with this function here...?

          -Frinny

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Ok I get it now the triple is the same as the double only it remove the sign.
            So you would want to perform the shift, then take the absolute value of it.

            [code=C#]

            int temp =(B - C);
            A= A>>temp;
            A=Math.Abs(A);

            [/code]
            Last edited by Plater; Apr 27 '10, 09:30 PM. Reason: corrected for the >>= thought

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              Shouldn't you be using the >>= assignment operator?
              in C# there is no >>> or >>>= operator, as you can use unsigned variables.
              A >>= (B - C);

              Make sure A is unsigned.

              Comment

              Working...