Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当将以下数字输入到 irb 时,我得到以下结果:
50 #=> 50 050 #=> 40 030 #=> 24 005 #=> 5
为什么050等于40而不是50, 030 == 30, 005 == 5?发生了什么?
050
40
50
030 == 30
005 == 5
以 0 开头的数字被解释为八进制数。
010 => 8 020 => 16 0777 => 511
八进制数。不仅仅是在 Ruby 中——大多数编程语言都认为,当你以零开头的数字时,它是以 8 为基数的。