Search code examples
c#rubytranslate

What does the following line of Ruby Do? "integer >> integer"


I am trying to convert some Ruby code into C# but I do not understand what the following line does. Specifically the "challenge >> 24" and similar parts.

challenge = sprintf("%c%c%c%c".encode("ASCII-8BIT"), x(challenge >> 24), x(challenge >> 16), x(challenge >> 8), x(challenge >> 0))

challenge is an integer that is defined earlier in the code. x is a method that takes an integer argument and returns an integer.

I am not expecting anyone to convert it to c# for me, just an explanation would be fine. Thanks.


Solution

  • >> is Binary Right Shift Operator.

    The left operands value is moved right by the number of bits specified by the right operand.

    This may be helpful: Rotate Bits Right operation in Ruby