18 lines
580 B
Common Lisp
18 lines
580 B
Common Lisp
(defpackage :all-your-base
|
|
(:use :cl)
|
|
(:export :rebase))
|
|
|
|
(in-package :all-your-base)
|
|
|
|
; conv converts a list representation to base 10 number
|
|
; This is complete but incorrect
|
|
(defun conv (l base)
|
|
(if (null l)
|
|
0
|
|
(+ (* (first l) (expt base (- (length l) 1)) (conv (rest l) base)))))
|
|
|
|
(defun unconv (number base exponent)
|
|
; (if (eq exponent -1) (calc-start-exponent number base) exponent)
|
|
; Slip the above into the following (or assign to new variable):
|
|
; (append (list (/ number base**exponent)) (unconv (mod number base**exponent) base (- exponent 1))
|
|
)
|