+ 10
Could someone kindly explain why this integer 3 turns into an array?
This is like a puzzle, please🙏 David George 🐉SHAROF🐉🇺🇿 Kuba Siekierzyński https://code.sololearn.com/c3b1oKi8gVY0/?ref=app
2 Antworten
+ 8
It is part of the definition of the integer class in Ruby. See https://ruby-doc.org/core-2.4.1/Integer.html
int[n] -> 0, 1
Bit Reference--Returns the +n+th bit in the binary representation of int, where int[0] is the least significant bit.
The binary representation of 3 is 11, so a[0] is the least significant bit, i.e. 1, and a[1] is the second least significant bit, which is also 1
The rest is as per your comments in the source file
+ 5
Thank you very much George 🙏