Last active
December 15, 2015 09:49
-
-
Save Denommus/5240902 to your computer and use it in GitHub Desktop.
Converts a byte array to a 32-bits unsigned int array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun byte-array-to-ui-32-bit-array (octet-array) | |
(declare (optimize (speed 3)) | |
(type (simple-array (unsigned-byte 8) (*)) octet-array)) | |
(if (/= (mod (length octet-array) 4) 0) | |
(make-array 0 :element-type '(unsigned-byte 32)) | |
(make-array (/ (length octet-array) 4) | |
:element-type '(unsigned-byte 32) | |
:initial-contents | |
(loop for i from 0 below (length octet-array) by 4 | |
for j = 0 then (1+ j) | |
for b0 of-type (unsigned-byte 8) = (aref octet-array i) | |
for b1 of-type (unsigned-byte 8) = (aref octet-array (+ i 1)) | |
for b2 of-type (unsigned-byte 8) = (aref octet-array (+ i 2)) | |
for b3 of-type (unsigned-byte 8) = (aref octet-array (+ i 3)) | |
for element = (logior b0 | |
(ash b1 8) | |
(ash b2 16) | |
(ash b3 24)) | |
collect element)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment