BitVecNumericalCompare
Description
Compare two bitvectors as unsigned integers. Treats bitvectors as unsigned binary numbers (LSB first).
Parameters
| Name | Direction | Description |
|---|---|---|
bv1 |
in | First bitvector |
bv2 |
in | Second bitvector |
Usage example (from documentation)
int result = BitVecNumericalCompare(&flags1, &flags2);Success
-1 if bv1 < bv2, 0 if equal, 1 if bv1 > bv2
Failure
Cannot fail; aborts on a corrupted magic via the validator.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:757:
}
int BitVecNumericalCompare(const BitVec *bv1, const BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);- In
BitVec.c:813:
}
int result = BitVecNumericalCompare(bv1, bv2);
// For two negatives, magnitude order is the opposite of value order
- In
Compare.c:177:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecNumericalCompare\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Compare.c:193:
// Numerical comparison should compare the integer values
int cmp_result = BitVecNumericalCompare(&bv1, &bv2);
bool result = (cmp_result > 0); // 5 > 3
- In
Compare.c:202:
BitVecPush(&bv2, true); // Also 101
result = result && (BitVecNumericalCompare(&bv1, &bv2) == 0);
// Clean up
- In
Compare.c:607:
// Numerically, 10 (2) < 101 (5)
result = result && (BitVecNumericalCompare(&bv1, &bv2) < 0);
// Test equal cases
- In
Compare.c:612:
BitVec bv3 = BitVecClone(&bv1);
result = result && !(BitVecCompare(&bv1, &bv3) < 0);
result = result && !(BitVecNumericalCompare(&bv1, &bv3) < 0);
// Test reverse comparison
- In
Compare.c:616:
// Test reverse comparison
result = result && !(BitVecCompare(&bv2, &bv1) < 0);
result = result && !(BitVecNumericalCompare(&bv2, &bv1) < 0);
// Clean up
- In
Compare.c:775:
// Cross-validate different comparison methods
// Numerical: 86 < 89, so bv1 < bv2
result = result && (BitVecNumericalCompare(&bv1, &bv2) < 0);
result = result && (BitVecCompare(&bv1, &bv2) < 0);- In
Compare.c:793:
}
if (BitVecNumericalCompare(&bv1, &bv2) < 0 && BitVecNumericalCompare(&bv2, &bv3) < 0) {
result = result && (BitVecNumericalCompare(&bv1, &bv3) < 0);
}- In
Compare.c:794:
if (BitVecNumericalCompare(&bv1, &bv2) < 0 && BitVecNumericalCompare(&bv2, &bv3) < 0) {
result = result && (BitVecNumericalCompare(&bv1, &bv3) < 0);
}- In
Compare.c:876:
// Unsigned: 01111111 (127) < 10000001 (129)
result = result && (BitVecNumericalCompare(&pos, &neg) < 0);
// Signed: 01111111 (+127) > 10000001 (-127)
- In
Compare.c:1307:
BitVecPush(&bv, true);
BitVecNumericalCompare(NULL, &bv); // must abort
BitVecDeinit(&bv);- In
Compare.c:1332:
// bv1 has its most-significant magnitude bit set, bv2 is all zero.
bool result = (BitVecNumericalCompare(&bv1, &bv2) > 0);
BitVecDeinit(&bv1);- In
Compare.c:1506:
BitVecPush(&bv, true);
BitVecNumericalCompare(&bv, NULL); // must abort
BitVecDeinit(&bv);
Last updated on