Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to compute the XOR of two binary strings and find the number of distinct values of this XOR which can be obtained, modulo 1,000,000,007 ( 109+7 ).


What I have tried:

#include<bits/stdc++.h>
using namespace std;
int performXOR(int x, int y) 
{ 
    int res = 0; 
      
    
    for (int i = 31; i >= 0; i--)                      
    { 
      
       bool b1 = x & (1 << i); 
       bool b2 = y & (1 << i); 
         
        
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);           
  
      
        res <<= 1; 
        res |= xoredBit; 
    } 
    return res; 
} 

int main(){
    
     int test;
    cin>>test;
    while(test--){
        
        long long a,b;
        int n;
        cin>>n;
        cin>>a>>b;
        //cout<<performXOR(a,b)<<endl;
        cout <<
        
        
        
        
        
    }
    
    return 0;
    
}
Posted
Updated 7-Dec-19 8:28am

1 solution

Quote:
how to compute the XOR of two binary strings and find the number of distinct values of this XOR which can be obtained, modulo 1,000,000,007 ( 109+7

Without correct context, this means nothing.

Your code is not related to strings!

This code :
C++
int performXOR(int x, int y) 
{ 
    int res = 0; 
    for (int i = 31; i >= 0; i--)                      
    { 
       bool b1 = x & (1 << i); 
       bool b2 = y & (1 << i); 
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);           
        res <<= 1; 
        res |= xoredBit; 
    } 
    return res; 
} 

can ve simplified to :
C++
int performXOR(int x, int y) 
{ 
    return x ^ y;
} 

Bitwise Operators in C/C++ - GeeksforGeeks[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900