Skip to content

BitVecAnd

BitVecAnd

Description

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

Parameters

Name Direction Description
result out Bitvector to store result in
a in First bitvector operand
b in Second bitvector operand

Usage example (from documentation)

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

Usage example (Cross-references)

Usage examples (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);
Last updated on