• 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
                • 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

    Strval16

    Interpret a string as a hexadecimal number.

    Signature
    (strval16 x) → value?
    Arguments
    x — Guard (stringp x).
    Returns
    value? — Type (or (natp value?) (not value?)).

    For example, (strval16 "1F") is 31. If the string is empty or has any non hexadecimal digit characters (0-9, A-F, a-f), we return nil.

    Definitions and Theorems

    Function: strval16

    (defun strval16 (x)
      (declare (xargs :guard (stringp x)))
      (declare (type string x))
      (declare (xargs :split-types t))
      (let ((acl2::__function__ 'strval16))
        (declare (ignorable acl2::__function__))
        (mbe :logic
             (let ((chars (explode x)))
               (and (consp chars)
                    (hex-digit-char-list*p chars)
                    (hex-digit-chars-value chars)))
             :exec
             (b* (((the unsigned-byte xl) (length x))
                  ((mv (the unsigned-byte val)
                       (the unsigned-byte len))
                   (parse-hex-from-string x 0 0 0 xl)))
               (and (not (eql 0 len))
                    (eql len xl)
                    val)))))

    Theorem: return-type-of-strval16

    (defthm return-type-of-strval16
      (b* ((value? (strval16 x)))
        (or (natp value?) (not value?)))
      :rule-classes :type-prescription)

    Theorem: istreqv-implies-equal-strval16-1

    (defthm istreqv-implies-equal-strval16-1
      (implies (istreqv x x-equiv)
               (equal (strval16 x) (strval16 x-equiv)))
      :rule-classes (:congruence))