Method: BitPack#on

Defined in:
ext/bitpack/bitpack_ext.c

#on(i) ⇒ Object

Sets the bit at index i. If i is greater than the current size of the BitPack object, then the size is expanded and the current append position is set to this index.

Example

>> bp = BitPack.new
=>
>> bp.on(0)
=> 1
>> bp.on(2)
=> 101
>> bp.on(7)
=> 10100001
>> bp.on(6)
=> 10100011


183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/bitpack/bitpack_ext.c', line 183

static VALUE bp_on(VALUE self, VALUE index)
{
    bitpack_t bp;

    Data_Get_Struct(self, struct _bitpack_t, bp);

    if (!bitpack_on(bp, NUM2ULONG(index))) {
        rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
                bitpack_get_error_str(bp));
    }

    return self;
}