2

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.

1
  • 1
    It's a bit-shift to the right. Commented Oct 25, 2012 at 10:20

2 Answers 2

3

>> 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

Sign up to request clarification or add additional context in comments.

2 Comments

In other words, it divides by 2^24
If they struggle understanding a shift I doubt they need a rotation.
2

Bit shift to the right, with the number to the right of the >> indicating how many times to shift.

C# has the >> operator too so translating that should be straightforward.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.