Source

ocaml-bert / bert.ml

Diff from to
       (* see http://www.erlang.org/doc/apps/erts/erl_ext_dist.html for details*)
     begin match (String.get local_bin 0) with
       | 'a' ->  (* SMALL_INTEGER_EXT *)
-	  Printf.printf "%d\n" (int_of_char (String.get local_bin 1));
 	  Ok( Int(int_of_char (String.get local_bin 1)), Str.string_after local_bin 2)
       | 'b' ->  (* INTEGER_EXT *)
 	  Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 5);
     end;;
 
 let print_binary bin = 
-  let rec p_bin i =
-    if i < (String.length bin) then begin
-      Printf.printf "%.2x," (int_of_char (String.get bin i));
-      p_bin (i+1)
-    end in
-    print_string "<<";
-    p_bin 0;
-    print_string ">>";;
+  let rec to_inverse_list bin_ list = 
+    if (String.length bin_)>0 then
+      to_inverse_list (Str.string_after bin_ 1) ((int_of_char (String.get bin_ 0))::list)
+    else list
+  in
+  let strs = List.fold_left (fun l c-> (Printf.sprintf "%.2x" c)::l ) [] (to_inverse_list bin []) in
+  let s = String.concat "," strs in
+    Printf.printf "<<%s>>" s;;
 
 let print_erlterm term = 
   let rec print_termlist rhs list =