Skip to content

Commit

Permalink
Added bits functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Izaakwltn authored and stylewarning committed Oct 25, 2024
1 parent c54feeb commit 19965eb
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions library/bits.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#:or
#:xor
#:not
#:shift))
#:shift
#:dpb
#:ldb))

(in-package #:coalton-library/bits)

Expand All @@ -36,7 +38,19 @@
(not "The bitwise logical `not` of two integers"
(:int -> :int))
(shift "The arithmetic left-shift of an integer by an integer number of bits"
(Integer -> :int -> :int))))
(Integer -> :int -> :int)))

(declare dpb (Bits :a => :a -> UFix -> UFix -> :a -> :a))
(define (dpb newbyte size position bitstring)
"Deposits a byte `newbyte` of size `size` into a bitstring `bitstring` at a position `position`."
(lisp :a (newbyte bitstring size position)
(cl:dpb newbyte (cl:byte size position) bitstring)))

(declare ldb (Bits :a => UFix -> UFix -> :a -> :a))
(define (ldb size position bitstring)
"Deposits a byte of size `size` into a bitstring at a position `position`."
(lisp :a (bitstring size position)
(cl:ldb (cl:byte size position) bitstring))))

#+sb-package-locks
(sb-ext:lock-package "COALTON-LIBRARY/BITS")
Expand Down

0 comments on commit 19965eb

Please sign in to comment.