BitVecRotateRight
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
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to rotate |
positions |
in | Number of positions to rotate right |
Usage example (from documentation)
BitVecRotateRight(&flags, 3);Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:937:
}
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
Last updated on