• 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
              • Hex-digit-char-theorems
            • 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

Hex-digit-char-value

Coerces a hex-digit-char-p character into a number.

Signature
(hex-digit-char-value x) → val
Arguments
x — Guard (hex-digit-char-p x).
Returns
val — Type (natp val).

For instance, (hex-digit-char-value #\a) is 10. For any non-hex-digit-char-p, 0 is returned.

Definitions and Theorems

Function: hex-digit-char-value$inline

(defun hex-digit-char-value$inline (x)
  (declare (xargs :guard (hex-digit-char-p x)))
  (declare (xargs :split-types t))
  (let ((acl2::__function__ 'hex-digit-char-value))
    (declare (ignorable acl2::__function__))
    (mbe :logic
         (b* (((unless (hex-digit-char-p x)) 0)
              (code (char-code x))
              ((when (<= (char-code #\a) code))
               (- code (- (char-code #\a) 10)))
              ((when (<= (char-code #\A) code))
               (- code (- (char-code #\A) 10))))
           (- code (char-code #\0)))
         :exec
         (b* (((the (unsigned-byte 8) code)
               (char-code (the character x)))
              ((when (<= 97 code))
               (the (unsigned-byte 8) (- code 87)))
              ((when (<= 65 code))
               (the (unsigned-byte 8) (- code 55))))
           (the (unsigned-byte 8) (- code 48))))))

Theorem: natp-of-hex-digit-char-value

(defthm natp-of-hex-digit-char-value
  (b* ((val (hex-digit-char-value$inline x)))
    (natp val))
  :rule-classes :type-prescription)

Theorem: ichareqv-implies-equal-hex-digit-char-value-1

(defthm ichareqv-implies-equal-hex-digit-char-value-1
  (implies (ichareqv x x-equiv)
           (equal (hex-digit-char-value x)
                  (hex-digit-char-value x-equiv)))
  :rule-classes (:congruence))

Theorem: hex-digit-char-value-upper-bound

(defthm hex-digit-char-value-upper-bound
  (< (hex-digit-char-value x) 16)
  :rule-classes ((:rewrite) (:linear)))

Theorem: unsigned-byte-p-of-hex-digit-char-value

(defthm unsigned-byte-p-of-hex-digit-char-value
  (unsigned-byte-p 4 (hex-digit-char-value x)))

Theorem: equal-of-hex-digit-char-value-and-hex-digit-char-value

(defthm equal-of-hex-digit-char-value-and-hex-digit-char-value
  (implies (and (hex-digit-char-p x)
                (hex-digit-char-p y))
           (equal (equal (hex-digit-char-value x)
                         (hex-digit-char-value y))
                  (ichareqv x y))))

Theorem: hex-digit-char-value-of-digit-to-char

(defthm hex-digit-char-value-of-digit-to-char
  (implies (and (natp n) (< n 16))
           (equal (hex-digit-char-value (digit-to-char n))
                  n)))

Subtopics

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