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 BitVecAnd function
    bool test_bitvec_and(void) {
    printf("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 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) {
    printf("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 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

BitVecRemove

BitVecRemove Description Remove a bit at given index from bitvector. Shifts all bits after the index to the left.

Read More

BitVecEntropy

BitVecEntropy Description Calculate information entropy of a bitvector. Entropy measures the randomness/information content of the bit pattern.

Read More

BitVecJaccardSimilarity

BitVecJaccardSimilarity Description Calculate Jaccard similarity between two bitvectors. Jaccard similarity = |intersection| / |union|

Read More