BitVecShiftRight

Table of Contents

BitVecShiftRight

Description

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

Parameters

NameDirectionDescription
bvinBitvector to shift
positionsinNumber of positions to shift right

Usage example (from documentation)

  BitVecShiftRight(&flags, 2);

Usage example (Cross-references)

    }
    
    void BitVecShiftRight(BitVec *bv, u64 positions) {
    ValidateBitVec(bv);
    if (positions == 0 || bv->length == 0) {
    // Test BitVecShiftRight function - CORRECTED EXPECTATIONS
    bool test_bitvec_shift_right(void) {
    printf("Testing BitVecShiftRight\n");
    
    BitVec bv = BitVecInit();
    // New bit[3] = 0 (filled)
    // Expected result: 1100
    BitVecShiftRight(&bv, 2);
    
    bool test_result = (bv.length == 4);
    result = result && (bv.length == 0);
    
    BitVecShiftRight(&bv, 3);
    result = result && (bv.length == 0);
    // Shift left by 1, then right by 1 - should NOT restore original (data loss)
    BitVecShiftLeft(&bv, 1);
    BitVecShiftRight(&bv, 1);
    
    // Should be different from original (lost MSB, gained LSB zero)
    }
    
    BitVecShiftRight(&bv, 10);
    result = result && (bv.length == 0);
    
    // Test NULL pointer for shift right - should abort
    BitVecShiftRight(NULL, 5);
    
    return false;
    // Test BitVecShiftRight function - CORRECTED EXPECTATIONS
    bool test_bitvec_shift_right(void) {
    printf("Testing BitVecShiftRight\n");
    
    BitVec bv = BitVecInit();
    // New bit[3] = 0 (filled)
    // Expected result: 1100
    BitVecShiftRight(&bv, 2);
    
    bool test_result = (bv.length == 4);
    result = result && (bv.length == 0);
    
    BitVecShiftRight(&bv, 3);
    result = result && (bv.length == 0);
    // Shift left by 1, then right by 1 - should NOT restore original (data loss)
    BitVecShiftLeft(&bv, 1);
    BitVecShiftRight(&bv, 1);
    
    // Should be different from original (lost MSB, gained LSB zero)
    }
    
    BitVecShiftRight(&bv, 10);
    result = result && (bv.length == 0);
    
    // Test NULL pointer for shift right - should abort
    BitVecShiftRight(NULL, 5);
    
    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

BitVecBestAlignment

BitVecBestAlignment Description Find best overlapping alignment between two bitvectors. Returns the offset that gives the best alignment score.

Read More

BitVecAnd

BitVecAnd Description Perform bitwise AND operation between two bitvectors. Result is stored in the first bitvector.

Read More