(num: i32, base: i32)
| 4 | "8","9","A","B","C","D","E","F"]; |
| 5 | |
| 6 | fn num2str_rec(num: i32, base: i32) -> String { |
| 7 | if num < base { |
| 8 | BASESTR[num as usize].to_string() |
| 9 | } else { |
| 10 | // 余数应加在末尾 |
| 11 | num2str_rec(num/base, base) + BASESTR[(num % base) as usize] |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | fn main() { |
| 16 | let num = 100; let sb = num2str_rec(num,2); |