• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • 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
                  • Insert-underscores
                • 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
          • String-listp
          • Stringp
          • Length
          • Search
          • Remove-duplicates
          • Position
          • Coerce
          • Concatenate
          • Reverse
          • String
          • Subseq
          • Substitute
          • String-upcase
          • String-downcase
          • Count
          • Char
          • String<
          • String-equal
          • String-utilities
          • String-append
          • String>=
          • String<=
          • String>
          • Hex-digit-char-theorems
          • String-downcase-gen
          • String-upcase-gen
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Oracle-eval
        • Defmacro-untouchable
        • <<
        • Primitive
        • Revert-world
        • Unmemoize
        • Set-duplicate-keys-action
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Fake-oracle-eval
        • Defopen
        • Sleep
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Hex

Hexify

Convert numbers into readable hex strings.

(hexify x) is a dumb but useful printing utility for displaying numbers in hex. It is typically used in cw statements, e.g.,:

ACL2 !> (cw "foo is ~s0~%" (str::hexify (1- (expt 2 32))))
foo is #uxFFFF_FFFF
NIL
ACL2 !>

The #ux is for compatibility with the ACL2::sharp-u-reader.

See also nat-to-dec-string which converts numbers into decimal strings (without underscores) and binify which is like hexify but for binary instead of hex.

Usage

(hexify x) always returns a stringp.

x must be an integer, string, or symbol; otherwise a hard-error will be caused.

Normally x is an integer. In this case, we convert it into an msb-first hex string with an underscore inserted every four characters. This makes it easier to read long values.

When x is a string we just return it unchanged.

When x is a symbol we just return its name.

Definitions and Theorems

Function: hexify

(defun hexify (x)
 (declare (xargs :guard t))
 (cond
  ((integerp x)
   (b*
    ((xsign (< x 0))
     (xabs (abs x))
     (chars (explode-atom xabs 16))
     (nice-chars
       (list*
            #\# #\u #\x
            (append (and xsign '(#\-))
                    (cons (first chars)
                          (insert-underscores (nthcdr 1 chars)))))))
    (implode nice-chars)))
  ((symbolp x) (symbol-name x))
  ((stringp x) x)
  (t (prog2$ (er hard? 'hexify
                 "Unexpected argument ~x0.~%" x)
             ""))))

Subtopics

Insert-underscores