diff options
| author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-11-07 06:11:09 -0300 |
|---|---|---|
| committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-11-07 06:11:09 -0300 |
| commit | a7909b294966eb861ce174aaa2c4696cb7cfa865 (patch) | |
| tree | 7a098ac1ddca6df20b66260bffcd00b9940761d7 /common.lisp | |
| parent | 6f2291bc7b15dad83d2fe70cb036e638ea8b3023 (diff) | |
| download | lempel-a7909b294966eb861ce174aaa2c4696cb7cfa865.tar.gz lempel-a7909b294966eb861ce174aaa2c4696cb7cfa865.zip | |
Bit stream decoder
Diffstat (limited to 'common.lisp')
| -rw-r--r-- | common.lisp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/common.lisp b/common.lisp index a061ca1..1c11703 100644 --- a/common.lisp +++ b/common.lisp @@ -7,3 +7,15 @@ (defstruct point (offset 0 :type fixnum) (size 0 :type fixnum)) + +(declaim (ftype (function ((array (unsigned-byte 1)) fixnum) (unsigned-byte 8)) bits->byte)) +(defun bits->byte (data index) + (let ((byte 0)) + (dotimes (i 8) + (setf byte (logior byte (ash (elt data (+ index i)) (- 7 i))))) + byte)) + +(declaim (ftype (function ((unsigned-byte 8) (array (unsigned-byte 1)) fixnum)) byte->bits)) +(defun byte->bits (data bits index) + (dotimes (i 8) + (setf (elt bits (+ index i)) (ash (logand data (ash 1 (- 7 i))) (- i 7))))) |
