BitVecInsertMultiple

Table of Contents

BitVecInsertMultiple

Description

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

Parameters

NameDirectionDescription
bvinBitvector to insert into
idxinPosition to insert at (0-based)
otherinBitvector whose bits to insert

Usage example (from documentation)

  BitVecInsertMultiple(&flags, 2, &other_flags);

Usage example (Cross-references)

    }
    
    void BitVecInsertMultiple(BitVec *bv, u64 idx, BitVec *other) {
    ValidateBitVec(bv);
    ValidateBitVec(other);
    // Test BitVecInsertMultiple function
    bool test_bitvec_insert_multiple(void) {
    printf("Testing BitVecInsertMultiple\n");
    
    BitVec bv     = BitVecInit();
    
    // Insert multiple bits from source
    BitVecInsertMultiple(&bv, 1, &source);
    
    // Check result: true, true, true, true, false
    
    bool test_bitvec_insert_multiple_edge_cases(void) {
    printf("Testing BitVecInsertMultiple edge cases\n");
    
    BitVec bv     = BitVecInit();
    
    // Test inserting empty bitvec
    BitVecInsertMultiple(&bv, 0, &empty);
    result = result && (bv.length == 0);
    // Test inserting single bit bitvec
    BitVecPush(&source, true);
    BitVecInsertMultiple(&bv, 0, &source);
    result = result && (bv.length == 1) && (BitVecGet(&bv, 0) == true);
    BitVecPush(&source, false);
    }
    BitVecInsertMultiple(&bv, 1, &source);
    result = result && (bv.length == 501);
    result = result && (BitVecGet(&bv, 1) == false);

Share :

Related Posts

BitVecNone

BitVecNone Description Check if no bits in bitvector match the given value.

Read More

BitVecRemoveRange

BitVecRemoveRange Description Remove multiple consecutive bits starting at a specific position. All bits after the removed range are shifted left.

Read More

BitVecFindLast

BitVecFindLast Description Find index of last occurrence of a specific bit value.

Read More