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) {
    WriteFmt("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) {
    WriteFmtLn("Testing BitVecShiftRight");
    
    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

BitVecInsert

BitVecInsert Description Insert a bit at given index in bitvector. Shifts all bits at and after the index to the right.

Read More

BitVecAnd

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

Read More

BitVecNot

BitVecNot Description Perform bitwise NOT operation on a bitvector. Result is stored in the first bitvector.

Read More