[求助]请帮忙给个十六进制转十进制的程序
请帮忙给个十六进制转十进制的程序,谢谢啦 (defun hex2ocx(hex)<br/> (setq hex_len (strlen hex)); hex_len=len(hex)<br/> (setq i 0);i=0<br/> (setq ocx 0);ocx=0<br/> (while (> hex_len 0);while hex_len >=0<br/> (setq m_hex (substr hex hex_len 1));m_hex=mid(hex,hex_len,1)<br/> (if (and (>= m_hex "a") (<= m_hex "f")) (setq tmp (- (ascii m_hex) 87)));if m_hex>="a" and m_hex <="f" tmp=asc(m_hex)-87<br/> (if (and (>= m_hex "A") (<= m_hex "F")) (setq tmp (- (ascii m_hex) 55)));if m_hex>="A" and m_hex <="F" tmp=asc(m_hex)-55<br/> (if (and (>= m_hex "0") (<= m_hex "9")) (setq tmp (atoi m_hex)));if m_hex>="0" and m_hex <="9" TMP=VAL(m_hex)<br/> (SETQ OCX (+ ocx (* tmp (expt 16 i))));计算N进制转10进制为:ocx=m*n^i-1+ocx //i为m所处N进制的位数,如个位为1<br/> (setq i (1+ i))<br/> (setq hex_len (1- hex_len))<br/> )<br/> ocx<br/> ) <p>(SETQ OCX (+ ocx (* tmp (expt 16 i))))</p><p>将这句里的"16"改成其它数可算出你要的任意进制的十进制数.</p><p>如改为"8",可计算八进制,如改为"2"可计算二进制.当然,上面的判断代码要进行相应的修改,</p><p>还有,程序的参数应该是字符串类型.</p>
页:
[1]