    /*
     *  call-seq:
     *     bv.to_a
     *
     *  Iterate through all the set bits in the bit vector adding the index of
     *  each set bit to an array. This is useful if you want to perform array
     *  methods on the bit vector. If you want to convert an array to a bit_vector
     *  simply do this;
     *
     *    bv = [1, 12, 45, 367, 455].inject(BitVector.new) {|bv, i| bv.set(i)}
     */
    VALUE
    frb_bv_to_a(VALUE self)
    {
        BitVector *bv;
        int bit;
        VALUE ary;
        GET_BV(bv, self);
        ary = rb_ary_new();
        bv_scan_reset(bv);
        if (bv->extends_as_ones) {
            while ((bit = bv_scan_next_unset(bv)) >= 0) {
                rb_ary_push(ary, INT2FIX(bit));
            }
        }
        else {
            while ((bit = bv_scan_next(bv)) >= 0) {
                rb_ary_push(ary, INT2FIX(bit));
            }
        }
        return ary;
    }