(defun bytes-to-int (array) (let ((arr-len (length array))) (when (< 4 (length array)) (error "can't make a 32bit integer from more than 4 8bit bytes")) (cond ((= arr-len 1) (aref array 0)) ((= arr-len 2) (logior (ash (aref array 0) 8) (aref array 1))) ((= arr-len 3) (logior (ash (aref array 0) 16) (ash (aref array 1) 8) (aref array 2))) ((= arr-len 4) (logior (ash (aref array 0) 24) (ash (aref array 1) 16) (ash (aref array 2) 8) (aref array 3)))))) (defun strip-trailing-0s (array) "Removes only 0's on the end of a sequence, it will skip 0's in the middle and returns a new sequence" (loop :for x :across (reverse array) :for i :downfrom (length array) :to 0 :unless (zerop x) :return (subseq array 0 i)))) ;;;;; NET-CONSTRUCT> (bytes-to-int #(1 0 0 0)) 16777216 (25 bits, #x1000000) NET-CONSTRUCT> (bytes-to-int (strip-trailing-0s #(1 0 0 0))) 1 (1 bit, #x1, #o1, #b1) ;value I want NET-CONSTRUCT> (bytes-to-int (strip-trailing-0s #(48 57 0 0))) 12345 (14 bits, #x3039) ;value I want NET-CONSTRUCT> (bytes-to-int #(48 57 0 0)) 809041920 (30 bits, #x30390000)