BitVecRotateLeft

Table of Contents

BitVecRotateLeft

Description

Rotate all bits in bitvector to the left by specified positions. Bits that fall off the left end wrap around to the right.

Parameters

NameDirectionDescription
bvinBitvector to rotate
positionsinNumber of positions to rotate left

Usage example (from documentation)

  BitVecRotateLeft(&flags, 5);

Usage example (Cross-references)

    }
    
    void BitVecRotateLeft(BitVec *bv, u64 positions) {
    ValidateBitVec(bv);
    if (positions == 0 || bv->length == 0) {
    
    // Test NULL pointer for rotate - should abort
    BitVecRotateLeft(NULL, 3);
    
    return false;
    // Test BitVecRotateLeft function
    bool test_bitvec_rotate_left(void) {
    WriteFmt("Testing BitVecRotateLeft\n");
    
    BitVec bv = BitVecInit();
    
    // Rotate left by 2 positions
    BitVecRotateLeft(&bv, 2);
    
    // Expected result: 1110 (1011 rotated left by 2)
    
    // Test rotate empty bitvec
    BitVecRotateLeft(&bv, 5);
    result = result && (bv.length == 0);
    // Test rotate by length (should be no-op)
    BitVecPush(&bv, false);
    BitVecRotateLeft(&bv, 2);
    result = result && (bv.length == 2);
    
    // Rotate left by 3, then right by 3
    BitVecRotateLeft(&bv, 3);
    BitVecRotateRight(&bv, 3);
    
    // Test rotate by multiple of length (should be no-op)
    BitVecRotateLeft(&bv, 16); // 8 * 2
    
    bool unchanged = true;
    BitVecPush(&bv, true); // 5 bits: 10101
    
    BitVecRotateLeft(&bv, 2);
    // 10101 -> 10110 (rotated left by 2)
    result = result && (BitVecGet(&bv, 0) == true);
    // Test BitVecRotateLeft function
    bool test_bitvec_rotate_left(void) {
    WriteFmtLn("Testing BitVecRotateLeft");
    
    BitVec bv = BitVecInit();
    
    // Rotate left by 2 positions
    BitVecRotateLeft(&bv, 2);
    
    // Expected result: 1110 (1011 rotated left by 2)
    
    // Test rotate empty bitvec
    BitVecRotateLeft(&bv, 5);
    result = result && (bv.length == 0);
    // Test rotate by length (should be no-op)
    BitVecPush(&bv, false);
    BitVecRotateLeft(&bv, 2);
    result = result && (bv.length == 2);
    
    // Rotate left by 3, then right by 3
    BitVecRotateLeft(&bv, 3);
    BitVecRotateRight(&bv, 3);
    
    // Test rotate by multiple of length (should be no-op)
    BitVecRotateLeft(&bv, 16); // 8 * 2
    
    bool unchanged = true;
    BitVecPush(&bv, true); // 5 bits: 10101
    
    BitVecRotateLeft(&bv, 2);
    // 10101 -> 10110 (rotated left by 2)
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test NULL pointer for rotate - should abort
    BitVecRotateLeft(NULL, 3);
    
    return false;

Share :

Related Posts

BitVecXor

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

Read More

BitVecSignedCompare

BitVecSignedCompare Description Compare two bitvectors as signed integers (MSB is sign bit).

Read More

BitVecIsSorted

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

Read More