home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / me_cd25.zip / MC2MUTT.ZIP / TOBASE.MUT < prev   
Text File  |  1992-11-09  |  563b  |  25 lines

  1. ; tobase(n,base): convert n (base 10) to base.  eg (tobase 10 16) => "A"
  2. ;    C Durland
  3.  
  4. (defun
  5.   mod (int n base)    ; n mod base = n - (n/base)*base
  6.     { (- n (* (/ n base) base)) }
  7.   tobase (int n base)
  8.   {
  9.     (if (< n base) (extract-elements "0123456789ABCDEF" n 1)
  10.       (concat
  11.         (tobase (/ n base) base)    ; tobase n/base base
  12.     (tobase (mod n base) base)    ; tobase (n mod base) base
  13.       )
  14.     )
  15.   }
  16. )
  17. (const NUMBER    0x03)
  18. (defun
  19.   MAIN
  20.   {
  21.     (msg (tobase
  22.     (convert-to NUMBER (ask "n = "))
  23.     (convert-to NUMBER (ask "base = "))))
  24.   })
  25.