Bits
1 Overview
2 Bit Type
Bit
bit?
one?
3 Bit Matrix Operations
bits-ref
bits-set!
4 Type Conversions
bit->boolean
boolean->bit
8.18

Bits🔗ℹ

 (require bits) package: bits

1 Overview🔗ℹ

This library provides utilities for treating Racket byte string as a bit matrix with a width of 8, allowing for direct, two-dimensional access or modification of individual bits.

2 Bit Type🔗ℹ

type

Bit

A type representing a single bit, defined as ( Zero One).

procedure

(bit? v)  Boolean

  v : Any
Returns #t if v is 0 or 1, #f otherwise.

Example:
> (:print-type bit?)

(-> Any Boolean : Bit)

procedure

(one? v)  Boolean

  v : Any
Returns #t if v is 1, #f otherwise.

Example:
> (:print-type one?)

(-> Any Boolean : One)

3 Bit Matrix Operations🔗ℹ

procedure

(bits-ref bs i j)  Bit

  bs : Bytes
  i : Integer
  j : Integer
Gets the bit at row i and column j from bs.

Examples:
> (define bs #"U")
> (bits-ref bs 0 0)

- : Integer [more precisely: Bit]

1

> (bits-ref bs 0 1)

- : Integer [more precisely: Bit]

0

procedure

(bits-set! bs i j bit)  Void

  bs : Bytes
  i : Integer
  j : Integer
  bit : Bit
Sets the bit at row i and column j in bs to bit.

Examples:
> (define bs (bytes 0))
> (bits-set! bs 0 7 1)
> bs

- : Bytes

#"\200"

> (bits-set! bs 0 7 0)
> bs

- : Bytes

#"\0"

4 Type Conversions🔗ℹ

procedure

(bit->boolean bit)  Boolean

  bit : Bit
Convert a bit to a boolean.

procedure

(boolean->bit bool)  Bit

  bool : Boolean
Convert a boolean to a bit.