XOR of two Binary Strings | C ++ Implementation to find the XOR of the two Binary Strings ; Function to find the XOR of the two Binary Strings ; Loop to iterate over the Binary Strings ; If the Character matches ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string xoring ( string a , string b , int n ) { string ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == b [ i ] ) ans += "0" ; else ans += "1" ; } return ans ; } int main ( ) { string a = "1010" ; string b = "1101" ; int n = a . length ( ) ; string c = xoring ( a , b , n ) ; cout << c << endl ; }