What does "<<" in "1000 << 16" mean in ruby?
What does "<<" in "1000 << 16" mean in ruby?
I know that for strings <<
can be used for concatenati开发者_运维百科on, but I don't understand what it does for int
s. Could someone please explain?
This is the left shift bitwise operator.
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.
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).
精彩评论