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 BitVecRotateLeft function
    bool test_bitvec_rotate_left(void) {
    printf("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 NULL pointer for rotate - should abort
    BitVecRotateLeft(NULL, 3);
    
    return false;
    // Test BitVecRotateLeft function
    bool test_bitvec_rotate_left(void) {
    printf("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 NULL pointer for rotate - should abort
    BitVecRotateLeft(NULL, 3);
    
    return false;

Share :

Related Posts

BitVecAnd

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

Read More

BitVecCorrelation

BitVecCorrelation Description Calculate Pearson correlation coefficient between two bitvectors. Treats bits as 0/1 values and computes linear correlation.

Read More

BitVecEntropy

BitVecEntropy Description Calculate information entropy of a bitvector. Entropy measures the randomness/information content of the bit pattern.

Read More