BitVecInsertPattern
- Function
- August 22, 2025
Table of Contents
BitVecInsertPattern
BitVecInsertPattern
Description
Insert a bit pattern from a byte at a specific position. Only the specified number of bits from the pattern are inserted.
Parameters
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to insert into |
idx | in | Position to insert at (0-based) |
pattern | in | Byte containing the bit pattern |
pattern_bits | in | Number of bits to take from pattern (1-8) |
Usage example (from documentation)
u8 pattern = 0x0B; // 1011 in binary
BitVecInsertPattern(&flags, 2, pattern, 4); // Insert 1011 at position 2
Usage example (Cross-references)
- In
BitVec.c:315
:
}
void BitVecInsertPattern(BitVec *bv, u64 idx, u8 pattern, u64 pattern_bits) {
ValidateBitVec(bv);
if (idx > bv->length) {
// Test BitVecInsertPattern function
bool test_bitvec_insert_pattern(void) {
printf("Testing BitVecInsertPattern\n");
BitVec bv = BitVecInit();
// Insert pattern 0x0B (1011 in binary) using 4 bits
u8 pattern = 0x0B;
BitVecInsertPattern(&bv, 1, pattern, 4);
// Check result: false, true, false, true, true, false
u8 pattern2 = 0x05;
BitVecInsertPattern(&bv2, 0, pattern2, 3);
// Check result: true, false, true, true (3 bits: 101)
bool test_bitvec_insert_pattern_edge_cases(void) {
printf("Testing BitVecInsertPattern edge cases\n");
BitVec bv = BitVecInit();
// Test inserting empty pattern (should be no-op)
BitVecInsertPattern(&bv, 0, 0x00, 0);
result = result && (bv.length == 0);
// Test inserting single bit pattern
BitVecInsertPattern(&bv, 0, 0x01, 1); // 1 bit pattern
result = result && (bv.length == 1);
// Test inserting 8-bit pattern
BitVecClear(&bv);
BitVecInsertPattern(&bv, 0, 0xAA, 8); // 10101010 pattern
result = result && (bv.length == 8);
result = result && (BitVecGet(&bv, 0) == false); // First bit of 0xAA
// Test NULL bitvec - should abort
BitVecInsertPattern(NULL, 0, 0xFF, 8);
return false;