SHARE
TWEET

Untitled

a guest Aug 19th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. let chiffres = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";;
  3. let chiffre v =
  4.   if 0 <= v && v < String.length chiffres then
  5.     String.sub chiffres v 1
  6.   else
  7.     "?(" ^ string_of_int v ^ ")"
  8. ;;
  9.  
  10. let rec ecriture b n =
  11.   if n = 0 then
  12.     ""
  13.   else
  14.     let alpha = n mod b in
  15.     let dernier = chiffre alpha in
  16.     let n' = n / b in
  17.     let reste = ecriture b n' in
  18.     reste ^ dernier
  19. ;;
  20.  
  21. let rec ecriture' b n =
  22.   if n = 0 then
  23.     ""
  24.   else
  25.     (ecriture' b (n / b)) ^ (chiffre (n mod b))
  26. ;;
  27.  
  28. let ecrit b n =
  29.   if n < 0 then
  30.     failwith "Pas de nombre negatif"
  31.   else if n = 0 then
  32.     print_endline "0"
  33.   else
  34.     print_endline (ecriture b n)
  35. ;;
  36.  
  37. let ecrit_16 = ecrit 16;;
  38.  
  39. ecrit_16 65535;;
  40. ecrit 37 36;;
  41. ecrit 37 65535;;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top