Skip to content
BitVecShiftLeft

BitVecShiftLeft

BitVecShiftLeft

Description

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

Parameters

Name Direction Description
bv in Bitvector to shift
positions in Number of positions to shift left

Usage example (from documentation)

  BitVecShiftLeft(&flags, 3);

Usage example (Cross-references)

Usage examples (Cross-references)
    
    // Shift operations
    void BitVecShiftLeft(BitVec *bv, u64 positions) {
        ValidateBitVec(bv);
        if (positions == 0 || bv->length == 0) {
    
        // Test NULL bitvec pointer - should abort
        BitVecShiftLeft(NULL, 1);
    
        return false;
    // Test BitVecShiftLeft function - CORRECTED EXPECTATIONS
    bool test_bitvec_shift_left(void) {
        WriteFmt("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 BitVecShiftLeft function - CORRECTED EXPECTATIONS
    bool test_bitvec_shift_left(void) {
        WriteFmtLn("Testing BitVecShiftLeft");
    
        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;
Last updated on