;转换为10进制 数值val 原始进制base
(defun baseToDecimal (base val / pos power1 result tmp)
(setq pos (1+ (strlen val))
power1 -1
result 0
val (strcase val)
)
(while (> (setq pos (1- pos)) 0)
(setq result
(+
result
(* (if (> (setq tmp (ascii (substr val pos 1))) 64)
(- tmp 55)
(- tmp 48)
)
(expt base (setq power1 (1+ power1)))
)
)
)
)
result
)
;10进制转换为其他进制 数值val 目标进制base;
(defun decimalToBase (base val / result tmp)
(setq result "")
(while (> val 0)
(setq result (strcat (if (> (setq tmp (rem val base)) 9)
(chr (+ tmp 55))
(itoa tmp)
)
result
)
val (fix (/ val base))
)
)
result
)
;进制转换 数值val 原始进制base1 目标进制base2;
(defun base1tobase2 (val base1 base2 / result)
(cond
((and (= (type val) 'INT) (= base1 10))
(setq result (decimalToBase base2 val))
)
((and (= (type val) 'STR) (= base1 10))
(setq result (decimalToBase base2 (read val)))
)
((= (type val) 'STR)
(setq result (decimalToBase base2 (baseToDecimal base1 val)))
)
(t nil)
)
(if (= base2 10) (read result) result)
)
posted on 2008-03-10 14:41
深藏记忆 阅读(75)
评论(0) 编辑 收藏 所属分类:
Vlisp之韵