fork download
  1. (* your code goes here *)(* hex to raw bytes *)
  2. let rec hex_to_raw hexstring =
  3. let rec hexraw hexstr rawstr =
  4. let tophex = String.sub hexstr 0 2 in
  5. let topint = int_of_string ("0x" ^ tophex) in
  6. let newrawstr = rawstr ^ (String.make 1 (Char.chr topint)) in
  7. let remlen = (String.length hexstr) - 2 in
  8. if remlen = 0 then newrawstr
  9. else hexraw (String.sub hexstr 2 remlen) newrawstr in
  10. hexraw hexstring "" ;;
  11.  
  12. let b64_to_raw b64string =
  13. b64string ;;
  14.  
  15. let raw_to_hex rawstring =
  16. rawstring ;;
  17.  
  18. let raw_to_b64 rawstring =
  19. rawstring ;;
  20.  
  21. Printf.printf "%s" (raw_to_b64 (hex_to_raw "badf00d"))
Runtime error #stdin #stdout #stderr 0.02s 2780KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Fatal error: exception Invalid_argument("String.sub")