Previous: Uniform Arrays, Up: Arrays


22.6.4 Bit Vectors

Bit vectors are a specific type of uniform array: an array of booleans with a single zero-based index.

They are displayed as a sequence of 0s and 1s prefixed by #*, e.g.,

     (make-uniform-vector 8 #t #f)
     ⇒ #*00000000
     
     #b(#t #f #t)
     ⇒ #*101
— Scheme Procedure: bit-count b bitvector
— C Function: scm_bit_count (b, bitvector)

Return the number of occurrences of the boolean b in bitvector.

— Scheme Procedure: bit-position bool bitvector k
— C Function: scm_bit_position (bool, bitvector, k)

Return the minimum index of an occurrence of bool in bitvector which is at least k (a non-negative integer not greater than the bitvector length), or #f if no bool occurs within the specified range.

— Scheme Procedure: bit-invert! bitvector
— C Function: scm_bit_invert_x (bitvector)

Replace each element in bitvector by its negation, and return it.

— Scheme Procedure: bit-set*! bitvector uve bool
— C Function: scm_bit_set_star_x (bitvector, uve, bool)

Set or clear bits in bitvector and return it.

If uve is a bit-vector, bitvector and uve must be of the same length. If bool is #t, uve is ored into bitvector. If bool is #f, the inversion of uve is anded into bitvector.

If uve is an unsigned integer vector, all the elements of uve must be between 0 (inclusive) and the length of bitvector (exclusive). The bits of bitvector corresponding to the indices in uve are set to bool.

— Scheme Procedure: bit-count* bitvector uve bool
— C Function: scm_bit_count_star (bitvector, uve, bool)

Return a count of uve-specified bool bits in bitvector.

If uve is a bit-vector, bitvector and uve must be of the same length. In this case, the count includes only those bits that are set (i.e., 1 or #t) in uve.

If uve is an unsigned integer vector, all the elements of uve must be between 0 (inclusive) and the length of bitvector (exclusive). In this case, the count includes only those bits corresponding to the indices in uve.