Sha256: 13194dc9314769e1ba93a411810dd446b3b53f67ce5ab7f95283001eabb04b6a

Contents?: true

Size: 433 Bytes

Versions: 68

Compression:

Stored size: 433 Bytes

Contents

open Base

let digit_to_int c =
  match c with
  | '0'..'9'  -> Some (Char.to_int(c) - 48)
  | 'a'..'f'  -> Some (Char.to_int(c) - 97 + 10)
  | 'A'..'F'  -> Some (Char.to_int(c) - 97 + 10)
  | _ -> None

let to_int hex_str =
  let rec go acc = function
    | []    -> acc
    | c::cs -> match digit_to_int c with
                    | Some n -> go (acc * 16 + n) cs
                    | None -> 0 in
  go 0 (String.to_list hex_str)

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.118 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.117 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.116 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.115 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.114 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.113 tracks/ocaml/exercises/hexadecimal/example.ml
trackler-2.2.1.111 tracks/ocaml/exercises/hexadecimal/example.ml