Skip to main content

bit-vector

bit-vector System Class

Class Precedence List:

bit-vector, vector, array, sequence, t

Description:

A bit vector is a vector the element type of which is bit.

The type bit-vector is a subtype of type vector, for bit-vector means (vector bit).

Compound Type Specifier Kind:

Abbreviating.

Compound Type Specifier Syntax:

(bit-vector [size])

Compound Type Specifier Arguments:

size—a non-negative fixnum, or the symbol *.

Compound Type Specifier Description:

This denotes the same type as the type (array bit (size)); that is, the set of bit vectors of size size.

See Also:

Section 2.4.8.4 (Sharpsign Asterisk), Section 22.1.3.6 (Printing Bit Vectors), Section 15.1.2.2 (Required Kinds of Specialized Arrays)

Expanded Reference: bit-vector

The bit-vector Type

A bit-vector is a vector whose elements are restricted to bits (0 or 1). Bit vectors are printed with the #* syntax.

(typep #*10110 'bit-vector)
=> T

(typep (make-array 5 :element-type 'bit :initial-element 0) 'bit-vector)
=> T

;; General vectors are NOT bit vectors
(typep (vector 0 1 0 1) 'bit-vector)
=> NIL

Creating Bit Vectors

;; Literal syntax
#*11001010
=> #*11001010

;; Using make-array
(make-array 8 :element-type 'bit :initial-element 0)
=> #*00000000

(make-array 4 :element-type 'bit :initial-contents '(1 0 1 1))
=> #*1011

Parameterized bit-vector Type

The bit-vector type can be parameterized by length.

(typep #*1011 '(bit-vector 4))
=> T

(typep #*1011 '(bit-vector 5))
=> NIL

Bit Vectors Support Logical Operations

The bit-and, bit-ior, bit-xor, and bit-not functions operate on entire bit vectors at once.

(bit-and #*1100 #*1010)
=> #*1000

(bit-ior #*1100 #*1010)
=> #*1110

(bit-not #*1100)
=> #*0011

Type Relationships

(subtypep 'bit-vector 'vector)
=> T
=> T

(subtypep 'simple-bit-vector 'bit-vector)
=> T
=> T