title: Program that changes a number from the base n to another base m
body: <p>I was just curious as to how to change a number from number base <code>m</code> to another base <code>n</code> with a Ruby program, not a gem. Has anyone done this and would like to share their thoughts or ideas? Just thought it would be fun to try out a program like this :)</p>
  
  <p>I've done it for bin to dec, dec to bin, dex to hex, hex to dec, but would want to know how to do it from m to n.</p>
  
  <pre><code>def bin2dec(num)
    sum = 0
    i = 0
  
    while i &lt; num.length
      sum += 2 ** i * num[num.length - i - 1].to_i
      i += 1
    end
  
    return sum
  end
  
  bin = gets.chomp
  out = bin2dec(bin)
  print out
  
  def dec2bin(dec)
    out = ""
    num = dec
  
    while num != 0
      out = "#{num % 2}" + out
      num = num / 2
    end
    return out
  end
  
  dec = gets.to_i
  print dec2bin(dec)
  </code></pre>