Convert a number from 0-15 into a hex character.
(hex-digit-to-char n) → *
ACL2 has a built-in version of this function, digit-to-char,
but
(defconstant *codes* (loop for i from 0 to 15 collect i)) ;; .217 seconds, no garbage (time (loop for i fixnum from 1 to 10000000 do (loop for c in *codes* do (str::hex-digit-to-char c)))) ;; .881 seconds, no garbage (time (loop for i fixnum from 1 to 10000000 do (loop for c in *codes* do (digit-to-char c))))
Function:
(defun hex-digit-to-char$inline (n) (declare (type (unsigned-byte 4) n)) (let ((acl2::__function__ 'hex-digit-to-char)) (declare (ignorable acl2::__function__)) (mbe :logic (digit-to-char n) :exec (if (< n 10) (code-char (the (unsigned-byte 8) (+ 48 n))) (code-char (the (unsigned-byte 8) (+ 55 n)))))))