This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.
Converting Between Numeric Bases | ||
---|---|---|
Code | Expected | Actual |
0b100 |
4 | 4 |
0o100 |
64 | 64 |
0x100 |
256 | 256 |
"1045".to_i(10) |
1045 | 1045 |
"-1001001".to_i(2) |
-73 | -73 |
"abc".to_i(16) |
2748 | 2748 |
"abc".to_i(20) |
4232 | 4232 |
"number".to_i(36) |
1442151747 | 1442151747 |
"zz1z".to_i(36) |
1678391 | 1678391 |
"abcdef".to_i(16) |
11259375 | 11259375 |
"AbCdEf".to_i(16) |
11259375 | 11259375 |
42.to_s(10) |
"42" | "42" |
-100.to_s(2) |
"-1100100" | "-1100100" |
255.to_s(16) |
"ff" | "ff" |
1442151747.to_s(36) |
"number" | "number" |
"6".to_i(2) |
0 | 0 |
"0".to_i(1) |
ArgumentError: illegal radix 1 ... |
ArgumentError: illegal radix 1 from (irb):17:in `to_i' from (irb):17 |
40.to_s(37) |
ArgumentError: illegal radix 37 ... |
ArgumentError: illegal radix 37 from (irb):18:in `to_s' from (irb):18 |