Reputation: 37
0xFFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFE_FFFFFC2F.ord
=> 115792089237316195423570985008687907853269984665640564039457584007908834671663
0xFFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFE_FFFFFC2F.to_i
=> 115792089237316195423570985008687907853269984665640564039457584007908834671663
Could somebody explain me why both of these methods return the same integer value? I'm not sure that i understand the method ord...
Returns the codepoint of the first character of the string, assuming a single-byte character encoding"
I found that, but here I've go a hex value and i used the method then get a decimal value, so "What the hex?" :D
PS: Is it decimal value for sure or am I wrong?
Upvotes: 1
Views: 337
Reputation: 23317
You've quoted String#ord
and here you call #ord
on Integer
- this value is not decimal, nor string, but integer.
ord → self
Returns the
int
itself.97.ord #=> 97 This method is intended for compatibility to character literals in Ruby 1.9.
Upvotes: 1