Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,12 @@
|
|||
let int_of_basen n str =
|
||||
match n with
|
||||
| 16 -> int_of_string("0x" ^ str)
|
||||
| 2 -> int_of_string("0b" ^ str)
|
||||
| 8 -> int_of_string("0o" ^ str)
|
||||
| _ -> failwith "unhandled"
|
||||
|
||||
let basen_of_int n d =
|
||||
match n with
|
||||
| 16 -> Printf.sprintf "%x" d
|
||||
| 8 -> Printf.sprintf "%o" d
|
||||
| _ -> failwith "unhandled"
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
let basen_of_int b n : string =
|
||||
let tab = "0123456789abcdefghijklmnopqrstuvwxyz" in
|
||||
let rec aux x l =
|
||||
if x < b
|
||||
then tab.[x] :: l
|
||||
else aux (x / b) (tab.[x mod b] :: l)
|
||||
in
|
||||
String.of_seq (List.to_seq (aux n []))
|
||||
|
||||
let basen_to_int b ds : int =
|
||||
let of_sym c =
|
||||
int_of_char c - match c with
|
||||
| '0' .. '9' -> int_of_char '0'
|
||||
| 'a' .. 'z' -> int_of_char 'a' - 10
|
||||
| 'A' .. 'Z' -> int_of_char 'A' - 10
|
||||
| _ -> invalid_arg "unkown digit"
|
||||
in
|
||||
String.fold_left (fun n d -> n * b + of_sym d) 0 ds
|
||||
Loading…
Add table
Add a link
Reference in a new issue