Skip to content

BitVecXor

Description

Perform bitwise XOR operation between two bitvectors. Result is stored in result. Operand lengths must match.

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)

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

Success

Returns to the caller. result->length == a->length; each bit result[i] == a[i] ^ b[i]. The operands are unchanged.

Failure

Function cannot fail. Mismatched operand lengths or invalid bitvectors are caller bugs and abort via LOG_FATAL.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    void BitVecXor(BitVec *result, BitVec *a, BitVec *b) {
        ValidateBitVec(result);
        ValidateBitVec(a);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecXor\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Perform XOR operation
        BitVecXor(&result, &bv1, &bv2);
    
        // Expected result: 0110 (1100 XOR 1010)
    
        // Test XOR with different lengths
        BitVecXor(&result, &bv1, &bv2);
        test_result = test_result && (BitVecLen(&result) == 8);
    
        // Test A XOR A = 0
        BitVecXor(&result, &bv1, &bv1);
        test_result = test_result && (BitVecLen(&result) == 16);
        for (int i = 0; i < 16; i++) {
    
        // Test A XOR B = B XOR A
        BitVecXor(&result1, &bv1, &bv2);
        BitVecXor(&result2, &bv2, &bv1);
        // Test A XOR B = B XOR A
        BitVecXor(&result1, &bv1, &bv2);
        BitVecXor(&result2, &bv2, &bv1);
    
        bool xor_commutative = true;
    
        // Test XOR on large data
        BitVecXor(&result, &bv1, &bv2);
        test_result = test_result && (BitVecLen(&result) == 1000);
    
        // Test NULL second operand - should abort
        BitVecXor(&result, NULL, &bv1);
    
        BitVecDeinit(&result);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmtLn("Testing BitVecXor");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Perform XOR operation
        BitVecXor(&result, &bv1, &bv2);
    
        // Expected result: 0110 (1100 XOR 1010)
    
        // Test XOR with different lengths
        BitVecXor(&result, &bv1, &bv2);
        test_result = test_result && (BitVecLen(&result) == 8);
    
        // Test A XOR A = 0
        BitVecXor(&result, &bv1, &bv1);
        test_result = test_result && (BitVecLen(&result) == 16);
        for (int i = 0; i < 16; i++) {
    
        // Test A XOR B = B XOR A
        BitVecXor(&result1, &bv1, &bv2);
        BitVecXor(&result2, &bv2, &bv1);
        // Test A XOR B = B XOR A
        BitVecXor(&result1, &bv1, &bv2);
        BitVecXor(&result2, &bv2, &bv1);
    
        bool xor_commutative = true;
    
        // Test XOR on large data
        BitVecXor(&result, &bv1, &bv2);
        test_result = test_result && (BitVecLen(&result) == 1000);
    
        // Test NULL second operand - should abort
        BitVecXor(&result, NULL, &bv1);
    
        BitVecDeinit(&result);
Last updated on