|
|
@ -10,13 +10,18 @@ uint ulong_len(ulong n) { // get the digit length of a number |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
fn digit(num: u32, idx: u32) -> u8 { |
|
|
|
fn digit(num: u64, idx: u32) -> u8 { |
|
|
|
// ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx)
|
|
|
|
// ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx)
|
|
|
|
(((num % (10_u32.pow(idx+1))) - (num % (10_u32.pow(idx))))/(10_u32.pow(idx))) as u8 |
|
|
|
(((num % (10_u64.pow(idx+1))) - (num % (10_u64.pow(idx))))/(10_u64.pow(idx))) as u8 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn numlen(num: u32) -> u8 { |
|
|
|
fn numlen(mut num: u64) -> u8 { |
|
|
|
let len: u8 = 0; |
|
|
|
let mut len: u8 = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if num == 0 { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while num != 0 { |
|
|
|
while num != 0 { |
|
|
|
num = num / 10; |
|
|
|
num = num / 10; |
|
|
|
len += 1; |
|
|
|
len += 1; |
|
|
@ -24,14 +29,19 @@ fn numlen(num: u32) -> u8 { |
|
|
|
len |
|
|
|
len |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn number_to_vec(num: u32) -> Vec<u8> { |
|
|
|
pub fn number_to_vec(num: u64) -> Vec<u8> { |
|
|
|
let out: Vec<u8> = Vec::new(); |
|
|
|
let mut out: Vec<u8> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
|
let len = numlen(num); |
|
|
|
let len = numlen(num); |
|
|
|
|
|
|
|
println!("len={len}"); |
|
|
|
|
|
|
|
|
|
|
|
for idx in 0..len { |
|
|
|
for idx in 0..len { |
|
|
|
out.push(digit(num, idx as u32));
|
|
|
|
let digit = digit(num, idx as u32); |
|
|
|
|
|
|
|
println!("\t{:?}", digit); |
|
|
|
|
|
|
|
out.push(digit);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("{:?}", out); |
|
|
|
|
|
|
|
|
|
|
|
out |
|
|
|
out |
|
|
|
} |
|
|
|
} |
|
|
|