• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • 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$
        • Defconst
        • Fast-alists
        • Defmacro
        • Loop$-primer
        • 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
            • Character-kinds
            • Html-encoding
            • 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
                  • 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
        • Miscellaneous
        • Output-controls
        • Bdd
        • Macros
        • Installation
        • Mailing-lists
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Hex

    Parse-hex-from-charlist

    Parse a hexadecimal number from the beginning of a character list.

    Signature
    (parse-hex-from-charlist x val len) → (mv val len rest)
    Arguments
    x — Characters to read from.
        Guard (character-listp x).
    val — Accumulator for the value of the hex digits we have read so far; typically 0 to start with.
        Guard (natp val).
    len — Accumulator for the number of hex digits we have read; typically 0 to start with.
        Guard (natp len).
    Returns
    val — Value of the initial hex digits as a natural number.
    len — Number of initial hex digits we read.
    rest — The rest of x, past the leading hex digits.

    This is like (parse-nat-from-charlist x val len), but deals with hex digits and returns their hexadecimal value.

    Definitions and Theorems

    Function: parse-hex-from-charlist

    (defun parse-hex-from-charlist (x val len)
      (declare (xargs :guard (and (character-listp x)
                                  (natp val)
                                  (natp len))))
      (declare (type unsigned-byte val len))
      (declare (xargs :split-types t))
      (let ((acl2::__function__ 'parse-hex-from-charlist))
        (declare (ignorable acl2::__function__))
        (cond ((atom x)
               (mv (lnfix val) (lnfix len) nil))
              ((hex-digit-char-p (car x))
               (parse-hex-from-charlist
                    (cdr x)
                    (the unsigned-byte
                         (+ (the unsigned-byte
                                 (hex-digit-char-value (car x)))
                            (the unsigned-byte
                                 (ash (the unsigned-byte (lnfix val))
                                      4))))
                    (the unsigned-byte
                         (+ 1 (the unsigned-byte (lnfix len))))))
              (t (mv (lnfix val) (lnfix len) x)))))

    Theorem: val-of-parse-hex-from-charlist

    (defthm val-of-parse-hex-from-charlist
      (equal (mv-nth 0 (parse-hex-from-charlist x val len))
             (+ (hex-digit-chars-value (take-leading-hex-digit-chars x))
                (ash (nfix val)
                     (* 4
                        (len (take-leading-hex-digit-chars x)))))))

    Theorem: len-of-parse-hex-from-charlist

    (defthm len-of-parse-hex-from-charlist
      (equal (mv-nth 1 (parse-hex-from-charlist x val len))
             (+ (nfix len)
                (len (take-leading-hex-digit-chars x)))))

    Theorem: rest-of-parse-hex-from-charlist

    (defthm rest-of-parse-hex-from-charlist
      (equal (mv-nth 2 (parse-hex-from-charlist x val len))
             (skip-leading-hex-digits x)))