BitVecShiftRight
- Function
- August 22, 2025
Table of Contents
BitVecShiftRight
BitVecShiftRight
Description
Shift all bits in bitvector to the right by specified positions. New bits on the left are filled with zeros.
Parameters
Name | Direction | Description |
---|---|---|
bv | in | Bitvector to shift |
positions | in | Number of positions to shift right |
Usage example (from documentation)
BitVecShiftRight(&flags, 2);
Usage example (Cross-references)
- In
BitVec.c:889
:
}
void BitVecShiftRight(BitVec *bv, u64 positions) {
ValidateBitVec(bv);
if (positions == 0 || bv->length == 0) {
// Test BitVecShiftRight function - CORRECTED EXPECTATIONS
bool test_bitvec_shift_right(void) {
printf("Testing BitVecShiftRight\n");
BitVec bv = BitVecInit();
// New bit[3] = 0 (filled)
// Expected result: 1100
BitVecShiftRight(&bv, 2);
bool test_result = (bv.length == 4);
result = result && (bv.length == 0);
BitVecShiftRight(&bv, 3);
result = result && (bv.length == 0);
// Shift left by 1, then right by 1 - should NOT restore original (data loss)
BitVecShiftLeft(&bv, 1);
BitVecShiftRight(&bv, 1);
// Should be different from original (lost MSB, gained LSB zero)
}
BitVecShiftRight(&bv, 10);
result = result && (bv.length == 0);
// Test NULL pointer for shift right - should abort
BitVecShiftRight(NULL, 5);
return false;
// Test BitVecShiftRight function - CORRECTED EXPECTATIONS
bool test_bitvec_shift_right(void) {
printf("Testing BitVecShiftRight\n");
BitVec bv = BitVecInit();
// New bit[3] = 0 (filled)
// Expected result: 1100
BitVecShiftRight(&bv, 2);
bool test_result = (bv.length == 4);
result = result && (bv.length == 0);
BitVecShiftRight(&bv, 3);
result = result && (bv.length == 0);
// Shift left by 1, then right by 1 - should NOT restore original (data loss)
BitVecShiftLeft(&bv, 1);
BitVecShiftRight(&bv, 1);
// Should be different from original (lost MSB, gained LSB zero)
}
BitVecShiftRight(&bv, 10);
result = result && (bv.length == 0);
// Test NULL pointer for shift right - should abort
BitVecShiftRight(NULL, 5);
return false;