Closed q9f closed 2 years ago
hex number not work
"00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i
=> 21
hex number not work
"00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i
=> 21
Makes sense 😮💨
hex number not work
"00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i => 21
You need to preprocess the JSON in this case. There is no way to know if a string is binary, octal, decimal, or hexadecimal.
decimal is enough.
I found you have hex string in test, so I have a try. do you run you test?
I found you have hex string in test, so I have a try. do you run you test?
test = "00000000000000000000000000000000000000000000021e19e0c9bab2400000".hex
=> 10000000000000000000000
test.to_s(16)
=> "21e19e0c9bab2400000"
For hexadecimal numbers, the argument to_i() must be 16.
irb(main):005:0> "00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i(16)
=> 10000000000000000000000
However, it is difficult to distinguish octal, decimal, or hexadecimal in the following pattern... 😢
irb(main):016:0> '000255'.to_i(8)
=> 173
irb(main):017:0> '000255'.to_i(10)
=> 255
irb(main):018:0> '000255'.to_i(16)
=> 597
decimal string is enough for most cases.
fix #110