我试图将一大批基数——10人改为16人,然后改为海尔。 我所看到的错误是Ocaml说,愤怒太大。
utop # let large_int = 11515195063862318899931685488813747395775516287289682636499965282714637259206269 ;;
Error: Integer literal exceeds the range of representable integers of type int
我也尝试利用Int64和类似的问题。
utop # let large_int = Int64.of_string "11515195063862318899931685488813747395775516287289682636499965282714637259206269";;
Exception: Failure "Int64.of_string".
这是我努力工作的更大法典。 它与下文中的例子一样运作。
(* convert from base10_to_base16 *)
let rec split_digits n =
if n = 0 then [] else
let (d, rest) = n mod 256, n / 256 in
d :: split_digits rest
let decode_base10 message =
let bytes_arr = List.rev (split_digits message) in
let decoded_message = String.concat "" (List.map (fun x -> String.make 1 (Char.chr x)) bytes_arr) in
decoded_message
let base10_message = 310400273487 (* base-10 number *)
let decoded_message = decode_base10 base10_message