1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| let hexa_from_int i = match i with
|n when 10>n -> string_of_int n
|10 -> "A"
|11 -> "B"
|12 -> "C"
|13 -> "D"
|14 -> "E"
|15 -> "F"
;;
let int_from_bin i =
(i/16, i mod 16)
;;
let hexa_from_bin i =
let (a,b) = int_from_bin i in
hexa_from_int a ^hexa_from_int b;;
let tes = open_in Sys.argv.(1) ;;
(*let rec string_from_channel chan =
try
match chan with
|chan -> hexa_from_bin (input_byte chan)^(string_from_channel chan)
with end_of_file -> "";;*)
let string_from_channel chan =
let str = ref "" in
let boucle =
try
while true do
str := (!str)^hexa_from_bin (input_byte chan)
done;
with end_of_file -> () in
boucle;
!str;;
let test = string_from_channel tes;;
let out = open_out "sortie.txt" ;;
output_string out test;;
close_out out;; |
Partager