开发者

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

开发者 https://www.devze.com 2023-03-11 21:41 出处:网络
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 ints. Could someon

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 ints. 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消