BitVecSignedCompare
Description
Compare two bitvectors as signed integers (MSB is sign bit).
Parameters
| Name | Direction | Description |
|---|---|---|
bv1 |
in | First bitvector |
bv2 |
in | Second bitvector |
Usage example (from documentation)
int result = BitVecSignedCompare(&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:796:
}
int BitVecSignedCompare(const BitVec *bv1, const BitVec *bv2) {
ValidateBitVec(bv1);
ValidateBitVec(bv2);- In
Compare.c:304:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecSignedCompare\n");
BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));- In
Compare.c:321:
// Positive should be greater than negative
bool result = (BitVecSignedCompare(&bv1, &bv2) > 0);
// Test two positives
- In
Compare.c:331:
// 3 > 1
result = result && (BitVecSignedCompare(&bv1, &bv2) > 0);
// Test equal signed values
- In
Compare.c:335:
// Test equal signed values
BitVec bv3 = BitVecClone(&bv1);
result = result && (BitVecSignedCompare(&bv1, &bv3) == 0);
// Clean up
- In
Compare.c:879:
// Signed: 01111111 (+127) > 10000001 (-127)
result = result && (BitVecSignedCompare(&pos, &neg) > 0);
// Clean up
- In
Compare.c:1353:
BitVecPush(&neg, true); // single bit set -> MSB set -> negative
bool result = (BitVecSignedCompare(&neg, &empty) < 0);
BitVecDeinit(&neg);- In
Compare.c:1373:
BitVecPush(&neg, true); // negative
bool result = (BitVecSignedCompare(&empty, &neg) > 0);
BitVecDeinit(&empty);- In
Compare.c:1395:
// negative < zero
bool result = (BitVecSignedCompare(&neg, &pos) < 0);
BitVecDeinit(&neg);- In
Compare.c:1416:
BitVecPush(&neg, true); // negative
bool result = (BitVecSignedCompare(&empty, &neg) > 0);
BitVecDeinit(&empty);- In
Compare.c:1437:
BitVecPush(&neg, true); // negative
bool result = (BitVecSignedCompare(&neg, &empty) < 0);
BitVecDeinit(&neg);- In
Compare.c:1461:
BitVecPush(&b, true);
bool result = (BitVecSignedCompare(&a, &b) == 0);
BitVecDeinit(&a);- In
Compare.c:1488:
// a has the larger magnitude, so a is the more-negative -> a < b.
bool result = (BitVecSignedCompare(&a, &b) < 0);
BitVecDeinit(&a);- In
Compare.c:1522:
BitVecPush(&bv, true);
BitVecSignedCompare(NULL, &bv); // must abort
BitVecDeinit(&bv);- In
Compare.c:1538:
BitVecPush(&bv, true);
BitVecSignedCompare(&bv, NULL); // must abort
BitVecDeinit(&bv);
Last updated on