A few hours ago, I wrote:
+---------------
| (defun valid-netmask-p (x &optional (addr-width 32))
| (and (plusp x)
| (= (integer-length x) addr-width)
| (let ((y (- (ash 1 addr-width) 1 x))) ; strip/cmpl 1st run of 1's
| (= y (1- (ash 1 (integer-length y))))))) ; also a run of 1's?
+---------------
Upon further reflection, I noticed a *much* simpler way to do this
[and probably much faster, since it doesn't use INTEGER-LENGTH]:
(defun valid-netmask-p (x &optional (addr-width 32))
(= x (- (ash 1 addr-width) (logand x (- x)))))
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607