2,764
社区成员




/*
* call-seq:
* str.to_i(base=10) -> integer
*
* Returns the result of interpreting leading characters in <i>str</i> as an
* integer base <i>base</i> (between 2 and 36). Extraneous characters past the
* end of a valid number are ignored. If there is not a valid number at the
* start of <i>str</i>, <code>0</code> is returned. This method never raises an
* exception when <i>base</i> is valid.
*
* "12345".to_i #=> 12345
* "99 red balloons".to_i #=> 99
* "0a".to_i #=> 0
* "0a".to_i(16) #=> 10
* "hello".to_i #=> 0
* "1100101".to_i(2) #=> 101
* "1100101".to_i(8) #=> 294977
* "1100101".to_i(10) #=> 1100101
* "1100101".to_i(16) #=> 17826049
*/
a = '01 01 01 01' #---> “1010101” ----> 16843009
a.gsub!(/\s/, '')
ia = a.to_i(16)
p ia
b = 'a1 01 b1 01' #---> “a101b101” ----> 2701242625
b.gsub!(/\s/, '')
ib = b.to_i(16)
p ib