Parse a hexadecimal number from the beginning of a character list.
(parse-hex-from-charlist x val len) → (mv val len rest)
This is like (parse-nat-from-charlist x val len), but deals with hex digits and returns their hexadecimal value.
Function:
(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:
(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:
(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:
(defthm rest-of-parse-hex-from-charlist (equal (mv-nth 2 (parse-hex-from-charlist x val len)) (skip-leading-hex-digits x)))