ruby将16进制转10进制问题
有一串16进制字符串,如“01 01 01 01”、“a1 01 b1 01”等
需要将其转成十进制,如“01 01 01 01”---> “1010101” ----> 16843009
“a1 01 b1 01”---> “a101b101” ----> 2701242625
如何操作?
请教各位达人~~~
[解决办法]
/*
* 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
*/