Convert numbers into readable hex strings.
(hexify x) is a dumb but useful printing utility for displaying numbers in hex. It is typically used in cw statements, e.g.,:
ACL2 !> (cw "foo is ~s0~%" (str::hexify (1- (expt 2 32)))) foo is #uxFFFF_FFFF NIL ACL2 !>
The
See also nat-to-dec-string which converts numbers into decimal strings (without
underscores) and binify which is like
(hexify x) always returns a stringp.
Normally
When
When
Function:
(defun hexify (x) (declare (xargs :guard t)) (cond ((integerp x) (b* ((xsign (< x 0)) (xabs (abs x)) (chars (explode-atom xabs 16)) (nice-chars (list* #\# #\u #\x (append (and xsign '(#\-)) (cons (first chars) (insert-underscores (nthcdr 1 chars))))))) (implode nice-chars))) ((symbolp x) (symbol-name x)) ((stringp x) x) (t (prog2$ (er hard? 'hexify "Unexpected argument ~x0.~%" x) ""))))