I've been reluctant to post in this thread because I don't have time to explain these excerpts from my library.
So I offer them "as is" for idea fodder, noting they were written for other purposes, and are only a small subset of a library of 60 related encoding/encryption/bit packing functions (there's other to/from flavors corresponding to other 2^x boundaries).
Anyway ...
(defun _Map32 ( )
;; © Michael Puckett
(setq **map32**
(vl-string->list
;; Note the omission of letters I,L,O,Q
"0123456789ABCDEFGHJKMNPRSTUVWXYZ"
)
)
(defun _Map32 ( ) **map32**)
**map32**
)
(defun _ToMap ( i map )
;; © Michael Puckett
( (lambda ( mask shift / result )
(while (not (zerop i))
(setq
result (cons (nth (logand mask i) map) result)
i (lsh i shift)
)
)
(vl-list->string result)
)
(1- (length map))
(- (fix (/ (log (length map)) (log 2))))
)
)
(defun _FromMap ( x map )
;; © Michael Puckett
( (lambda ( x map shift result )
(while x
(setq result (+ result (length (member (car x) map))))
(if (setq x (cdr x)) (setq result (lsh result shift)))
)
result
)
(mapcar 'chr (vl-string->list x))
(mapcar 'chr (reverse (cdr map)))
(fix (/ (log (length map)) (log 2)))
0
)
)
(defun _To32 ( i )
;; © Michael Puckett
(_ToMap i (_Map32))
)
(defun _From32 ( x )
;; © Michael Puckett
(_FromMap x (_Map32))
)
(defun _Inc32 ( x i )
;; © Michael Puckett
(_To32 (+ i (_From32 x)))
)
The range of values that can be represented by these functions corresponds to the range of integers that AutoCAD can represent:
(expt 2 31) >> -2147483648, (_To32 (expt 2 31)) >> "2000000"
(1- (expt 2 31)) >> +2147483647, (_To32 (1- (expt 2 31))) >> "1ZZZZZZ"
To understand why (expt 2 31) yeilds a negative value the uninitiated may wish to read articles on "two's complement".
Code performs no hand handholding. See _Map32 function for acceptable data, notwithstanding AutoCAD's integer limits. Pass stupid data, crash, get stupid results or an std.
Examples:
(_Inc32 "0" 1) >> "1"
(_Inc32 "0" -1) >> "3ZZZZZZ"
(_From32 "3ZZZZZZ") >> -1
(_Inc32 "0" 31) >> "Z"
(_Inc32 "0" 32) >> "10"
(_Inc32 "Z" 1) >> "10"
(_Inc32 "ZZ" 1) >> "100"
(_Inc32 "Z" -1) >> "Y"
(_Inc32 "ZZ" -1) >> "ZY"
(_Inc32 "ABC" 1) >> "ABD"
(_Inc32 "ABC" 10) >> "ABP"
(_Inc32 "ABC" 100) >> "AEG"
(_Inc32 "ABC" -1) >> "ABB"
(_Inc32 "ABC" -10) >> "AB2"
(_Inc32 "ABC" -100) >> "A88"
FWIW / Have fun.
Cheers.