Convert numbers into readable binary strings, fixing the number of digits printed
(binify x) is identical to hexify-width except that it produces binary output instead of hex output.
Function:
(defun binify-width (x width) (declare (xargs :guard (posp width))) (b* ((width (mbe :logic (if (posp width) width 1) :exec width))) (cond ((integerp x) (b* ((xsign (< x 0)) (xabs (abs x)) (chars (explode-atom xabs 2)) (fixed-chars (cond ((<= width (len chars)) (nthcdr (- (len chars) width) chars)) (t (append (make-list (- width (len chars)) :initial-element #\0) chars)))) (nice-chars (list* #\# #\u #\b (append (and xsign '(#\-)) (cons (first fixed-chars) (insert-underscores (nthcdr 1 fixed-chars))))))) (implode nice-chars))) ((symbolp x) (symbol-name x)) ((stringp x) x) (t (prog2$ (er hard? 'binify-width "Unexpected argument ~x0.~%" x) "")))))