let to_base_n n base =
  let digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" in
  if n = 0 then "0"
  else begin
    let m = ref (abs n) in
    let acc = ref "" in
    while !m > 0 do
      acc := String.make 1 digits.[!m mod base] ^ !acc;
      m := !m / base
    done;
    if n < 0 then "-" ^ !acc else !acc
  end

;;

String.length (to_base_n 255 16) +
String.length (to_base_n 1024 2) +
String.length (to_base_n 100 10) +
String.length (to_base_n 0 16)
