Skip to content
BitVecSignedCompare

BitVecSignedCompare

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);

Returns

-1 if bv1 < bv2, 0 if equal, 1 if bv1 > bv2

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    int BitVecSignedCompare(BitVec *bv1, BitVec *bv2) {
        ValidateBitVec(bv1);
        ValidateBitVec(bv2);
    // Test BitVecSignedCompare function
    bool test_bitvec_signed_compare(void) {
        WriteFmt("Testing BitVecSignedCompare\n");
    
        BitVec bv1 = BitVecInit();
    
        // Positive should be greater than negative
        bool result = (BitVecSignedCompare(&bv1, &bv2) > 0);
    
        // Test two positives
    
        // 3 > 1
        result = result && (BitVecSignedCompare(&bv1, &bv2) > 0);
    
        // Test equal signed values
        // Test equal signed values
        BitVec bv3 = BitVecClone(&bv1);
        result     = result && (BitVecSignedCompare(&bv1, &bv3) == 0);
    
        // Clean up
    
        // Signed: 01111111 (+127) > 10000001 (-127)
        result = result && (BitVecSignedCompare(&pos, &neg) > 0);
    
        // Clean up
Last updated on