7 Bitports
(require binaryio/bitport) | package: binaryio-lib |
Added in version 1.2 of package binaryio-lib.
An output bitport is like an output string port (open-output-bytes), except that instead of accumulating bytes, it accumulates bits and packs them into a byte string.
procedure
(output-bitport? v) → boolean?
v : any/c
procedure
(open-output-bitport [msf?]) → output-bitport?
msf? : boolean? = #t
If msf? is true, then the bytes produced by the bitport (through output-bitport-get-output) represents the sequence in most significant first bit order.
procedure
(output-bitport-partial bp) → sbv?
bp : output-bitport?
procedure
(output-bitport-write-bit bp bit) → void?
bp : output-bitport? bit : (or/c 0 1)
Equivalent to (output-bitport-write-sbv (make-sbv bit 1)).
procedure
(output-bitport-write-sbv bp sbv) → void?
bp : output-bitport? sbv : sbv?
procedure
(output-bitport-get-output bp [ #:reset? reset? #:pad pad-sbv])
→
bytes? exact-nonnegative-integer? bp : output-bitport? reset? : boolean? = #f pad-sbv : sbv? = empty-sbv
If bp contains an incomplete byte (because bits-written is not divisible by 8), then the final byte of the output is padded with the lower bits of pad-sbv (extended with zeros if more padding bits are needed). If bits-written is divisible by 8, no padding is included.
If reset? is true, then all written bits are removed from bp.
procedure
(output-bitport-pad bp [#:pad pad-sbv])
→ exact-nonnegative-integer? bp : output-bitport? pad-sbv : sbv? = 0
procedure
(bytes-bit-set? bs bit-index) → boolean?
bs : bytes? bit-index : exact-nonnegative-integer?
The byte string is interpreted as big-endian in the following sense: within a single byte in bs, bits are indexed started with the most significant bit first. So for example, (bytes-bit-set? (bytes b) 0) is (bitwise-bit-set? b 7).
> (bytes-bit-set? (bytes 1 128) 0) #f
> (bytes-bit-set? (bytes 1 128) 7) #t
> (bytes-bit-set? (bytes 1 128) 8) #t
> (bytes-bit-set? (bytes 1 128) 15) #f