Skip to content

Instantly share code, notes, and snippets.

@moxaj
Created September 6, 2016 15:01
Show Gist options
  • Save moxaj/7757f4ce58e6333397f583d5c5c82e83 to your computer and use it in GitHub Desktop.
Save moxaj/7757f4ce58e6333397f583d5c5c82e83 to your computer and use it in GitHub Desktop.
(defmacro !integer [buffer offset size le? value]
`(doto ~buffer
~@(map (fn [i]
`(aset ~(+ offset (if le? i (- size i 1)))
(unchecked-byte
(bit-and (unsigned-bit-shift-right ~value ~(* 8 i))
0xFF))))
(range size))))
(defmacro ?integer [buffer offset size le?]
(reduce (fn [code i]
`(bit-or ~code
(bit-shift-left (aget ~buffer ~(+ offset i))
~(* 8 (if le? i (- size i 1))))))
0
(range size)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment