;; | --------------------------------------------------------------------------- ;; | MI_htoi ;; | --------------------------------------------------------------------------- ;; | Function : Convert from hexadecimal string to ineteger ;; | Argument : 'str' - Hexadecimal String ;; | Return : The decimal integer ;; | Update : August 6, 1998 ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | --------------------------------------------------------------------------- (defun MI_htoi (str / prmpt num int) (setq int 0 str (strcase str) ;force str uppercase prmpt (strcat "\nInvalid hex value " str) ;build error prompt ) (while ;process each (/= 0 (setq num (substr str 1 1) ;get 1st character str (substr str 2) ;remainder num (ascii num) ;return ascii value ) ) (if (setq num ;return base 10 value (cond ( (< num 48) (prompt prmpt)) ;not a number ( (< num 58) (- num 48)) ;convert 0-9 ( (< num 65) (prompt prmpt)) ;not a number ( (< num 71) (- num 55)) ;convert A-F ( T (prompt prmpt)) ) ) (setq int (+ int (* (expt 16 (strlen str)) num))) ;accumulate ) ) )