何だかビットベクタの実装を披露するのが流行っているようなので :-) 一つ
書いてみました.

<http://www.os.xaxon.ne.jp/~kjana/ruby/bitvec.tar.gz>


Integer と BitVector に対するビット演算も用意してありますが,今の
Bignum の実装に大きくよってます.

# 今なら英語に似た言語の文書つき :-)


-- 
柳川和久 @ 東大阪市 . 大阪府                             September 12, 2000
「田園の,日差しの農場?」「ふざけるにゃ!」

=begin = Name bitvec. = Synopsis require "bitvec" vec = BitVector.new vec[10] = 1 puts vec[10] msk = BitVector.new msk.set 0x000f puts vec&msk : = Description This extension library provides BitVector, an Integer like object one can access an its specified bit without extra objects. Initially BitVector has length sufficient to hold bits specified at creation (default is 16). A vector is expanded on referencing or modifying a bit that is not in the vector, or being set a longer bit mask by BitVector#set. Bitwise operations with BitVectors or Bignums are available. Resulting BitVector's length are equal to receiver --- on a operation res = vec&msk, the length of res is equal to that of vec. If msk is shorter than vec, computations are done as if upper bits of msk is 0. = Methods == Class Methods --- BitVector.new(len = 16) Creates new bit vector. If len is specified, initial length of BitVector is determined for effectively holding the len bits. == Instance Methods --- BitVector#set(val) Sets val as a bit mask. Namely each bit of the vector is set according to the bit of the val. val must be an Integer or a BitVector. --- BitVector#[](bit) References the bit bit of the BitVector. --- BitVector#[]=(bit, val) Sets the bit bit of the BitVector. val must be 0 or 1. --- BitVector#&(val) --- BitVector#and(val) Returns bitwise and of the BitVector and val. val must be an Integer or a BitVector. #and is a destructive form. That is it modifies self. --- BitVector#|(val) --- BitVector#or(val) Returns bitwise or of the BitVector and val. val must be an Integer or a BitVector. #or is a destructive form. That is it modifies self. --- BitVector#^(val) --- BitVector#xor(val) Returns bitwise exclusive or of the BitVector and val. val must be an Integer or a BitVector. #xor is a destructive form. That is it modifies self. --- BitVector#~@ --- BitVector#not Returns bitwise not of the BitVector. #not is a destructive form. That is it modifies self. --- BitVector#to_i Returns Integer representation of BitVector. = Bugs Current implementation is strongly depends on the structure of Bignum. Therefore does not have enough portability. =end