Next: Cutting and Pasting Bit Strings, Previous: Construction of Bit Strings, Up: Bit Strings

— procedure: **bit-string-ref**` bit-string k`

Returns

`#t`

if thekth bit is 1; otherwise returns`#f`

.Kmust be a valid index ofbit-string.

— procedure: **bit-string-set!**` bit-string k`

Sets the

kth bit inbit-stringto 1 and returns an unspecified value.Kmust be a valid index ofbit-string.

— procedure: **bit-string-clear!**` bit-string k`

Sets the

kth bit inbit-stringto 0 and returns an unspecified value.Kmust be a valid index ofbit-string.

— procedure: **bit-substring-find-next-set-bit**` bit-string start end`

Returns the index of the first occurrence of a set bit in the substring of

bit-stringfromstart(inclusive) toend(exclusive). If none of the bits in the substring are set`#f`

is returned. The index returned is relative to the whole bit string, not substring.The following procedure uses

`bit-substring-find-next-set-bit`

to find all the set bits and display their indexes:(define (scan-bitstring bs) (let ((end (bit-string-length bs))) (let loop ((start 0)) (let ((next (bit-substring-find-next-set-bit bs start end))) (if next (begin (write-line next) (if (< next end) (loop (+ next 1)))))))))