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 NULL pointer for shift right - should abort
    BitVecShiftRight(NULL, 5);
    
    return false;
    // 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 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

BitVecShiftLeft

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

Read More

BitVecOr

BitVecOr Description Perform bitwise OR operation between two bitvectors. Result is stored in the first bitvector.

Read More

BitVecIsSorted

BitVecIsSorted Description Check if bits in bitvector are in sorted order. Useful for certain algorithms and data structures.

Read More