BitVecShiftLeft

Table of Contents

BitVecShiftLeft

Description

Shift all bits in bitvector to the left by specified positions. New bits on the right are filled with zeros.

Parameters

NameDirectionDescription
bvinBitvector to shift
positionsinNumber of positions to shift left

Usage example (from documentation)

  BitVecShiftLeft(&flags, 3);

Usage example (Cross-references)

    
    // Shift operations
    void BitVecShiftLeft(BitVec *bv, u64 positions) {
    ValidateBitVec(bv);
    if (positions == 0 || bv->length == 0) {
    // Test BitVecShiftLeft function - CORRECTED EXPECTATIONS
    bool test_bitvec_shift_left(void) {
    printf("Testing BitVecShiftLeft\n");
    
    BitVec bv = BitVecInit();
    // After shift left by 2: bits move to higher indices, lower indices filled with 0
    // New: 0011 (bit 0=0, bit 1=0, bit 2=1, bit 3=0) - but we shift out the high bits
    BitVecShiftLeft(&bv, 2);
    
    // After shift left by 2, implementation should clear bits that shift out
    
    // Test shift empty bitvec
    BitVecShiftLeft(&bv, 5);
    result = result && (bv.length == 0);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    BitVecShiftLeft(&bv, 0);
    result = result && (bv.length == 2);
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test shift larger than length (should clear all bits)
    BitVecShiftLeft(&bv, 10);
    result = result && (bv.length == 0); // Should clear when shifting everything out
    BitVecPush(&bv, i % 2 == 0);
    }
    BitVecShiftLeft(&bv, 1);
    result = result && (bv.length == 1000);
    
    // Shift left by 1, then right by 1 - should NOT restore original (data loss)
    BitVecShiftLeft(&bv, 1);
    BitVecShiftRight(&bv, 1);
    }
    
    BitVecShiftLeft(&bv, 8);
    result = result && (bv.length == 0);
    BitVecPush(&bv, false);
    
    BitVecShiftLeft(&bv, 2);
    result = result && (bv.length == 3);
    result = result && (BitVecGet(&bv, 0) == false); // filled with 0
    }
    
    BitVecShiftLeft(&result, 100);
    test_result = test_result && (result.length == 1000);
    
    // Test NULL bitvec pointer - should abort
    BitVecShiftLeft(NULL, 1);
    
    return false;
    // Test BitVecShiftLeft function - CORRECTED EXPECTATIONS
    bool test_bitvec_shift_left(void) {
    printf("Testing BitVecShiftLeft\n");
    
    BitVec bv = BitVecInit();
    // After shift left by 2: bits move to higher indices, lower indices filled with 0
    // New: 0011 (bit 0=0, bit 1=0, bit 2=1, bit 3=0) - but we shift out the high bits
    BitVecShiftLeft(&bv, 2);
    
    // After shift left by 2, implementation should clear bits that shift out
    
    // Test shift empty bitvec
    BitVecShiftLeft(&bv, 5);
    result = result && (bv.length == 0);
    BitVecPush(&bv, true);
    BitVecPush(&bv, false);
    BitVecShiftLeft(&bv, 0);
    result = result && (bv.length == 2);
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test shift larger than length (should clear all bits)
    BitVecShiftLeft(&bv, 10);
    result = result && (bv.length == 0); // Should clear when shifting everything out
    BitVecPush(&bv, i % 2 == 0);
    }
    BitVecShiftLeft(&bv, 1);
    result = result && (bv.length == 1000);
    
    // Shift left by 1, then right by 1 - should NOT restore original (data loss)
    BitVecShiftLeft(&bv, 1);
    BitVecShiftRight(&bv, 1);
    }
    
    BitVecShiftLeft(&bv, 8);
    result = result && (bv.length == 0);
    BitVecPush(&bv, false);
    
    BitVecShiftLeft(&bv, 2);
    result = result && (bv.length == 3);
    result = result && (BitVecGet(&bv, 0) == false); // filled with 0
    }
    
    BitVecShiftLeft(&result, 100);
    test_result = test_result && (result.length == 1000);
    
    // Test NULL bitvec pointer - should abort
    BitVecShiftLeft(NULL, 1);
    
    return false;

Share :

Related Posts

BitVecRemove

BitVecRemove Description Remove a bit at given index from bitvector. Shifts all bits after the index to the left.

Read More

BitVecEntropy

BitVecEntropy Description Calculate information entropy of a bitvector. Entropy measures the randomness/information content of the bit pattern.

Read More

BitVecXor

BitVecXor Description Perform bitwise XOR operation between two bitvectors. Result is stored in the first bitvector.

Read More