anchor.diff:                       (error "Invalid hex digit ~A" char1))
                      (when (= v2 +dt-invalid+)
                        (error "Invalid hex digit ~A" char2))
  -                   (funcall writer (+ (* v1 16) v2))))))
  +                   (funcall writer (+ (* (logand v1 #xf) 16)
  +                                      (logand v2 #xf)))))))
       (declare (inline do-decode))
       (decode-dispatch string #'do-decode)))
   
  
positive.code: 
  (register-descriptor-and-constructors :base16 (base16-format-descriptor)
                                        #'make-base16-encode-state
                                        #'make-base16-encode-state)
  (register-descriptor-and-constructors :hex (base16-format-descriptor)
                                        #'make-hex-encode-state
                                        #'make-hex-encode-state)
  
negative.code:   (base16-encoder state output input output-start output-end
                    input-start input-end lastp #'identity))
  
  (defun base16-decode-table (case-fold)
    (if case-fold
        (case-fold-decode-table *base16-decode-table*
                                *base16-encode-table*)
        *base16-decode-table*))
  
  (defstruct (base16-decode-state
               (:include decode-state)
               (:copier nil)
               (:constructor %make-base16-decode-state
                             (table
                              &aux (descriptor (base16-format-descriptor)))))
    (bits 0 :type (unsigned-byte 8))
    (n-bits 0 :type fixnum)
    (table *base16-decode-table* :read-only t :type decode-table))
  
  (defun make-base16-decode-state (case-fold map01)
    (declare (ignore map01))
    (%make-base16-decode-state (base16-decode-table case-fold)))
  
  (defun make-hex-decode-state (case-fold map01)
    (declare (ignore case-fold map01))
    (%make-base16-decode-state (base16-decode-table t)))
  
  (defun base16-decoder (state output input
                         output-index output-end
                         input-index input-end lastp converter)
    (declare (type base16-decode-state state))
    (declare (type simple-octet-vector output))
    (declare (type index output-index output-end input-index input-end))
    (declare (type function converter))
    (let ((bits (base16-decode-state-bits state))
          (n-bits (base16-decode-state-n-bits state))
          (table (base16-decode-state-table state)))
      (declare (type (unsigned-byte 8) bits))
      (tagbody
       START
         (when (base16-decode-state-finished-input-p state)
           (go FLUSH-BITS))
       OUTPUT-AVAILABLE-CHECK
         (when (< n-bits 8)
           (go INPUT-AVAILABLE-CHECK))
       OUTPUT-SPACE-CHECK
         (when (>= output-index output-end)
           (go DONE))
       DO-OUTPUT
         (setf (aref output output-index) bits
               bits 0
               n-bits 0)
         (incf output-index)
         (go INPUT-AVAILABLE-CHECK)
       INPUT-AVAILABLE-CHECK
         (when (>= input-index input-end)
           (go DONE))
       DO-INPUT
         (assert (< n-bits 8))
         (let* ((v (aref input input-index))
                (c (dtref table (funcall converter v))))
           (when (= c +dt-invalid+)
             (error "invalid hex digit ~A at position ~D" v input-index))
           (incf input-index)
           (cond
             ((= n-bits 0)
              (setf bits (* (logand c #xf) 16)
                    n-bits 4)
              (go INPUT-AVAILABLE-CHECK))
             ((= n-bits 4)
              (setf bits (+ bits (logand c #xf))
                    n-bits 8)
              (go OUTPUT-SPACE-CHECk))))
       DONE
         (unless lastp
           (go RESTORE-STATE))
         (setf (base16-decode-state-finished-input-p state) t)
       FLUSH-BITS
         (when (zerop n-bits)
           (go RESTORE-STATE))
       FLUSH-OUTPUT-CHECK
         (when (>= output-index output-end)
           (go RESTORE-STATE))
       DO-FLUSH-OUTPUT
         (when (= n-bits 4)
           (error "attempting to decode an odd number of hex digits"))
         (setf (aref output output-index) bits
               bits 0
               n-bits 0)
       RESTORE-STATE
         (setf (base16-decode-state-n-bits state) n-bits
               (base16-decode-state-bits state) bits))
      (values input-index output-index)))
  
  (defun string->octets/base16 (state output input
                                output-index output-end
                                input-index input-end lastp)
    (declare (type simple-string input))
    (base16-decoder state output input output-index output-end
                    input-index input-end lastp #'char-code))
  
  (defun octets->octets/decode/base16 (state output input
                                       output-index output-end
                                       input-index input-end lastp)
    (declare (type simple-octet-vector input))
    (base16-decoder state output input output-index output-end
                    input-index input-end lastp #'identity))
  
  (defun decode-octets-base16 (string start end length table writer)
    (declare (type index start end))
  