• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Html-encoding
        • Character-kinds
        • Substrings
        • Strtok
        • Equivalences
        • Url-encoding
        • Lines
        • Explode-implode-equalities
        • Ordering
        • Numbers
          • Decimal
          • Hex
            • Parse-hex-from-string
            • Hex-digit-char-p
            • Nat-to-hex-chars
            • Parse-hex-from-charlist
            • Hex-digit-chars-value
            • Hex-digit-char-value
            • Take-leading-hex-digit-chars
            • Hexify
            • Hex-digit-char-listp
            • Hex-digit-char-list*p
            • Hex-digit-string-p
            • Strval16
            • Skip-leading-hex-digits
            • Nat-to-hex-string
            • Hexify-width
            • Nonzero-hex-digit-char-p
            • Nat-to-hex-string-list
            • Revappend-nat-to-hex-chars
            • Hex-digit-to-char
              • Hex-digit-char-theorems
            • Nat-to-hex-string-size
          • Octal
          • Binary
        • Pad-trim
        • Coercion
        • Std/strings/digit-to-char
        • Substitution
        • Symbols
      • Std/osets
      • Std/io
      • Std/basic
      • Std/system
      • Std/typed-lists
      • Std/bitsets
      • Std/testing
      • Std/typed-alists
      • Std/stobjs
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Hex

Hex-digit-to-char

Convert a number from 0-15 into a hex character.

Signature
(hex-digit-to-char n) → *

ACL2 has a built-in version of this function, digit-to-char, but hex-digit-to-char is faster:

(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))))

Definitions and Theorems

Function: hex-digit-to-char$inline

(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)))))))

Subtopics

Hex-digit-char-theorems
Some theorems about the library functions str::hex-digit-char-value and str::hex-digit-to-char.