Non-decimal radices/Convert: Difference between revisions

(added common lisp)
Line 317:
//optional special case for hex:
i = +('0x'+s) //hexadecimal base 16, if s='1a' then i=26.</javascript>
 
=={{header|OCaml}}==
<ocaml>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"</ocaml>
 
# basen_of_int 16 26 ;;
- : string = "1a"
# int_of_basen 16 "1a" ;;
- : int = 26
 
=={{header|Perl}}==