1

What does "<<" in "1000 << 16" mean in ruby?

I know that for strings << can be used for concatenation, but I don't understand what it does for ints. Could someone please explain?

3 Answers 3

8

This is the left shift bitwise operator.

3

What it should do is take the binary representation of one thousand and shift the bits to the left sixteen spaces. Effectively, it multiplies the number by 65,536.

2

You can look it up in RDoc: http://www.ruby-doc.org/core/classes/Fixnum.html#M001102

fix << count → integer

Shifts fix left count positions (right if count is negative).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.