It's very interesting that integers can access indexes like and array.
So we can make things like this:
puts 3[0] returns 1.
puts 3[1] returns 1.
puts 3[2] returns 0.
What is all about that?
From the docs for Integer#[]:
Bit Reference---Returns the
nth bit in the binary representation ofint, whereint[0]is the least significant bit.
3 is 11 in binary, so 3[0] (the least significant one) and 3[1] are 1 and everything else is 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With