Answer to Question #183086 in C++ for Rana

Question #183086

Given two arrays A[n] & B[n] containing bit strings representing sets A & B

respectively, write a code fragment to construct bit string representing the set

A⨁B


1
Expert's answer
2021-04-21T18:22:43-0400

C++ code for calculating Xor of two array string

XOR function take two input and when these value of input are different the xor of those input  is 1 if both value are same it is 0

For example

A = 1 , B = 0 so A xor B will be 1

A = 1 , B = 1 so A xor B will be 0

Complete code for this problem is

#include<bits/stdc++.h>
using namespace std;

//Declaring function doXor with 3 parameters
string doXor(string A, string B, int len){
string ans = "";
        
        
        for (int i = 0; i < len; i++)//for loop till the length of the variable
        {
        
                if (A[i] == B[i])// doing xor of the variables
                        ans += "0";
                else
                        ans += "1";
        }
        return ans; // returning the value of xor
}


int main()
{
        string A = "1010";
        string B = "1101";// Declaring two string with binary value
        int len = A.length();
        //storing the length of any one variable as lenghth is sae of both
        string c = doXor(A, B, len);//calling and passing argument in function 
cout <<"Xor of the two string is : "<< c << endl;//printing the value of xor 
}

C++ code for calculating Xor of two array string

XOR function take two input and when these value of input are different the xor of those input  is 1 if both value are same it is 0

For example

A = 1 , B = 0 so A xor B will be 1

A = 1 , B = 1 so A xor B will be 0

Complete code for this problem is

#include<bits/stdc++.h>
using namespace std;

//Declaring function doXor with 3 parameters
string doXor(string A, string B, int len){
string ans = "";
        
        
        for (int i = 0; i < len; i++)//for loop till the length of the variable
        {
        
                if (A[i] == B[i])// doing xor of the variables
                        ans += "0";
                else
                        ans += "1";
        }
        return ans; // returning the value of xor
}


int main()
{
        string A = "1010";
        string B = "1101";// Declaring two string with binary value
        int len = A.length();
        //storing the length of any one variable as lenghth is sae of both
        string c = doXor(A, B, len);//calling and passing argument in function 
cout <<"Xor of the two string is : "<< c << endl;//printing the value of xor 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS