BitVecAnd

Table of Contents

BitVecAnd

Description

Perform bitwise AND operation between two bitvectors. Result is stored in the first bitvector.

Parameters

NameDirectionDescription
resultoutBitvector to store result in
ainFirst bitvector operand
binSecond bitvector operand

Usage example (from documentation)

  BitVecAnd(&result, &flags1, &flags2);

Usage example (Cross-references)

    }
    
    void BitVecAnd(BitVec *result, BitVec *a, BitVec *b) {
    ValidateBitVec(result);
    ValidateBitVec(a);
    
    // Test NULL pointer - should abort
    BitVecAnd(NULL, &bv, &bv2);
    
    BitVecDeinit(&bv);
    
    // Test NULL result pointer - should abort
    BitVecAnd(NULL, &bv1, &bv2);
    
    BitVecDeinit(&bv1);
    // Test BitVecAnd function
    bool test_bitvec_and(void) {
    WriteFmt("Testing BitVecAnd\n");
    
    BitVec bv1    = BitVecInit();
    
    // Perform AND operation
    BitVecAnd(&result, &bv1, &bv2);
    
    // Expected result: 1000 (1101 AND 1010)
    // Test operations on empty bitvecs
    BitVec result_bv = BitVecInit();
    BitVecAnd(&result_bv, &bv1, &bv2);
    result = result && (result_bv.length == 0);
    BitVecPush(&bv2, false);
    
    BitVecAnd(&result_bv, &bv1, &bv2);
    result = result && (result_bv.length >= 1); // Should handle gracefully
    
    // Test AND with different lengths (result should be min length)
    BitVecAnd(&result, &bv1, &bv2);
    test_result = test_result && (result.length == 4);
    BitVecPush(&bv2, false);
    
    BitVecAnd(&result, &bv1, &bv2);
    test_result = test_result && (result.length == 1);
    test_result = test_result && (BitVecGet(&result, 0) == false);
    
    // Test A AND A = A
    BitVecAnd(&result, &bv1, &bv1);
    bool and_identity = true;
    for (int i = 0; i < 16; i++) {
    }
    
    BitVecAnd(&result, &bv1, &bv2);
    bool and_zero = true;
    for (int i = 0; i < 16; i++) {
    
    // Test A AND B = B AND A
    BitVecAnd(&result1, &bv1, &bv2);
    BitVecAnd(&result2, &bv2, &bv1);
    // Test A AND B = B AND A
    BitVecAnd(&result1, &bv1, &bv2);
    BitVecAnd(&result2, &bv2, &bv1);
    
    bool and_commutative = true;
    
    // Test AND on large data
    BitVecAnd(&result, &bv1, &bv2);
    test_result = test_result && (result.length == 1000);
    // Test BitVecAnd function
    bool test_bitvec_and(void) {
    WriteFmtLn("Testing BitVecAnd");
    
    BitVec bv1    = BitVecInit();
    
    // Perform AND operation
    BitVecAnd(&result, &bv1, &bv2);
    
    // Expected result: 1000 (1101 AND 1010)
    // Test operations on empty bitvecs
    BitVec result_bv = BitVecInit();
    BitVecAnd(&result_bv, &bv1, &bv2);
    result = result && (result_bv.length == 0);
    BitVecPush(&bv2, false);
    
    BitVecAnd(&result_bv, &bv1, &bv2);
    result = result && (result_bv.length >= 1); // Should handle gracefully
    
    // Test AND with different lengths (result should be min length)
    BitVecAnd(&result, &bv1, &bv2);
    test_result = test_result && (result.length == 4);
    BitVecPush(&bv2, false);
    
    BitVecAnd(&result, &bv1, &bv2);
    test_result = test_result && (result.length == 1);
    test_result = test_result && (BitVecGet(&result, 0) == false);
    
    // Test A AND A = A
    BitVecAnd(&result, &bv1, &bv1);
    bool and_identity = true;
    for (int i = 0; i < 16; i++) {
    }
    
    BitVecAnd(&result, &bv1, &bv2);
    bool and_zero = true;
    for (int i = 0; i < 16; i++) {
    
    // Test A AND B = B AND A
    BitVecAnd(&result1, &bv1, &bv2);
    BitVecAnd(&result2, &bv2, &bv1);
    // Test A AND B = B AND A
    BitVecAnd(&result1, &bv1, &bv2);
    BitVecAnd(&result2, &bv2, &bv1);
    
    bool and_commutative = true;
    
    // Test AND on large data
    BitVecAnd(&result, &bv1, &bv2);
    test_result = test_result && (result.length == 1000);
    
    // Test NULL pointer - should abort
    BitVecAnd(NULL, &bv, &bv2);
    
    BitVecDeinit(&bv);
    
    // Test NULL result pointer - should abort
    BitVecAnd(NULL, &bv1, &bv2);
    
    BitVecDeinit(&bv1);

Share :

Related Posts

BitVecSignedCompare

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

Read More

BitVecIsSorted

BitVecIsSorted Description Check if bits in bitvector are in sorted order. Useful for certain algorithms and data structures.

Read More

BitVecDisjoint

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

Read More