BitVecRotateLeft
- Function
- August 22, 2025
Table of Contents
BitVecRotateLeft
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
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to rotate |
positions | in | Number of positions to rotate left |
Usage example (from documentation)
BitVecRotateLeft(&flags, 5);
Usage example (Cross-references)
- In
BitVec.c:913
:
}
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;