BitVecRotateRight

Table of Contents

BitVecRotateRight

Description

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

Parameters

NameDirectionDescription
bvinBitvector to rotate
positionsinNumber of positions to rotate right

Usage example (from documentation)

  BitVecRotateRight(&flags, 3);

Usage example (Cross-references)

    }
    
    void BitVecRotateRight(BitVec *bv, u64 positions) {
    ValidateBitVec(bv);
    if (positions == 0 || bv->length == 0) {
    // Test BitVecRotateRight function
    bool test_bitvec_rotate_right(void) {
    WriteFmt("Testing BitVecRotateRight\n");
    
    BitVec bv = BitVecInit();
    
    // Rotate right by 1 position
    BitVecRotateRight(&bv, 1);
    
    // Expected result: 1101 (1011 rotated right by 1)
    // Test rotate by 0
    BitVecPush(&bv, true);
    BitVecRotateRight(&bv, 0);
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test large rotate amount
    BitVecRotateRight(&bv, 1000);
    result = result && (bv.length == 2);
    // Rotate left by 3, then right by 3
    BitVecRotateLeft(&bv, 3);
    BitVecRotateRight(&bv, 3);
    
    // Should restore original
    // Test BitVecRotateRight function
    bool test_bitvec_rotate_right(void) {
    WriteFmtLn("Testing BitVecRotateRight");
    
    BitVec bv = BitVecInit();
    
    // Rotate right by 1 position
    BitVecRotateRight(&bv, 1);
    
    // Expected result: 1101 (1011 rotated right by 1)
    // Test rotate by 0
    BitVecPush(&bv, true);
    BitVecRotateRight(&bv, 0);
    result = result && (BitVecGet(&bv, 0) == true);
    
    // Test large rotate amount
    BitVecRotateRight(&bv, 1000);
    result = result && (bv.length == 2);
    // Rotate left by 3, then right by 3
    BitVecRotateLeft(&bv, 3);
    BitVecRotateRight(&bv, 3);
    
    // Should restore original

Share :

Related Posts

BitVecNot

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

Read More

BitVecAnd

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

Read More

BitVecXor

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

Read More