BitVecInsert

Table of Contents

BitVecInsert

Description

Insert a bit at given index in bitvector. Shifts all bits at and after the index to the right.

Parameters

NameDirectionDescription
bvinBitvector to insert bit into
idxinIndex at which to insert bit (0-based)
valueinBit value to insert (true/false)

Usage example (from documentation)

  BitVecInsert(&flags, 5, true);

Usage example (Cross-references)

    }
    
    void BitVecInsert(BitVec *bitvec, u64 idx, bool value) {
    ValidateBitVec(bitvec);
    if (idx > bitvec->length) {
    // Insert new pattern
    for (u64 i = 0; i < new_pattern->length; i++) {
    BitVecInsert(bv, pos + i, BitVecGet(new_pattern, i));
    }
    // Insert new pattern
    for (u64 i = 0; i < new_pattern->length; i++) {
    BitVecInsert(bv, match_pos + i, BitVecGet(new_pattern, i));
    }
    // Test BitVecInsert single bit function
    bool test_bitvec_insert_single(void) {
    WriteFmt("Testing BitVecInsert (single bit)\n");
    
    BitVec bv = BitVecInit();
    
    // Insert at index 0 (empty bitvector)
    BitVecInsert(&bv, 0, true);
    
    // Check first bit
    
    // Insert at the end
    BitVecInsert(&bv, 1, false);
    
    // Check bits
    
    // Insert in the middle
    BitVecInsert(&bv, 1, true);
    
    // Check all bits

Share :

Related Posts

BitVecInsertRange

BitVecInsertRange Description Insert multiple bits of the same value at a specific position. All existing bits at and after the position are shifted right.

Read More

BitVecInsertMultiple

BitVecInsertMultiple Description Insert all bits from another bitvector at a specific position. All existing bits at and after the position are shifted right.

Read More

BitVecPush

BitVecPush Description Push a bit to the end of bitvector. Grows the bitvector if necessary.

Read More