BitVecSignedCompare

Table of Contents

BitVecSignedCompare

Description

Compare two bitvectors as signed integers (MSB is sign bit).

Parameters

NameDirectionDescription
bv1inFirst bitvector
bv2inSecond bitvector

Usage example (from documentation)

  int result = BitVecSignedCompare(&flags1, &flags2);

Usage example (Cross-references)

    }
    
    int BitVecSignedCompare(BitVec *bv1, BitVec *bv2) {
    ValidateBitVec(bv1);
    ValidateBitVec(bv2);
    // Test BitVecSignedCompare function
    bool test_bitvec_signed_compare(void) {
    printf("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

Share :

Related Posts

BitVecEquals

BitVecEquals Description Test equality between two bitvectors. Two bitvectors are equal if they have the same length and all bits match.

Read More

BitVecWeightCompare

BitVecWeightCompare Description Compare two bitvectors by their Hamming weights (number of 1s).

Read More

BitVecDisjoint

BitVecDisjoint Description Check if two bitvectors are disjoint (have no common 1-bits).

Read More