The "literal" way to do this would be something like
(defvar *array* (make-array 4 :element-type 'bit :initial-element 0))
(setf (bit *array* 2) (mod (1+ (bit *array* 2)) 2))
(print *array*) ;; ==> #*0010
(setf (bit *array* 2) (mod (1+ (bit *array* 2)) 2))
(print *array*) ;; ==> #*0000
or as self-contained function:
(defun nbit-flip (bitset index)
(setf (bit bitset index) (mod (1+ (bit bitset index)) 2))
bitset)
You could use (logandlogxor 1 ...) instead of (mod ... 2) and lognot to replacedo the 1+ giving:flipping like
(defun nbit-flip (bitset index)
(setf (bit bitset index) (logandlogxor 1 (lognot (bit bitset index))))
bitset)
Just stick to that which may or may not signalsignals your intention moremost clearly.