• 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
              • Basic-nat-to-hex-chars
              • Nat-to-hex-chars-aux
            • 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
            • 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

Nat-to-hex-chars

Convert a natural number into a list of hexadecimal bits.

Signature
(nat-to-hex-chars n) → chars
Arguments
n — Guard (natp n).
Returns
chars — Type (hex-digit-char-list*p chars).

For instance, (nat-to-hex-chars 31) is (#\1 #\F).

This is like ACL2's built-in function explode-nonnegative-integer, except that it doesn't deal with accumulators and is limited to base-16 numbers. These simplifications lead to particularly nice rules, e.g., about hex-digit-chars-value, and somewhat better performance:

;; Times reported by an AMD FX-8350, Linux, 64-bit CCL:

;; .732 seconds, 942 MB allocated
(progn (gc$)
       (time (loop for i fixnum from 1 to 10000000 do
                   (str::nat-to-hex-chars i))))

;; 3.71 seconds, 942 MB allocated
(progn (gc$)
       (time (loop for i fixnum from 1 to 10000000 do
          (explode-nonnegative-integer i 16 nil))))

Definitions and Theorems

Function: nat-to-hex-chars$inline

(defun nat-to-hex-chars$inline (n)
  (declare (xargs :guard (natp n)))
  (let ((acl2::__function__ 'nat-to-hex-chars))
    (declare (ignorable acl2::__function__))
    (or (nat-to-hex-chars-aux n nil)
        '(#\0))))

Theorem: hex-digit-char-list*p-of-nat-to-hex-chars

(defthm hex-digit-char-list*p-of-nat-to-hex-chars
  (b* ((chars (nat-to-hex-chars$inline n)))
    (hex-digit-char-list*p chars))
  :rule-classes :rewrite)

Theorem: true-listp-of-nat-to-hex-chars

(defthm true-listp-of-nat-to-hex-chars
  (and (true-listp (nat-to-hex-chars n))
       (consp (nat-to-hex-chars n)))
  :rule-classes :type-prescription)

Theorem: character-listp-of-nat-to-hex-chars

(defthm character-listp-of-nat-to-hex-chars
  (character-listp (nat-to-hex-chars n)))

Theorem: nat-to-hex-chars-one-to-one

(defthm nat-to-hex-chars-one-to-one
  (equal (equal (nat-to-hex-chars n)
                (nat-to-hex-chars m))
         (equal (nfix n) (nfix m))))

Theorem: hex-digit-chars-value-of-nat-to-hex-chars

(defthm hex-digit-chars-value-of-nat-to-hex-chars
  (equal (hex-digit-chars-value (nat-to-hex-chars n))
         (nfix n)))

Subtopics

Basic-nat-to-hex-chars
Logically simple definition that is similar to nat-to-hex-chars.
Nat-to-hex-chars-aux