I am having trouble understanding where my logic is going wrong

I have written the code however when i dry run it, seems fine but when i run it in the code it gives faulty answers

hello @shibangi it can happen!
please share your code by saving it on ide.codinglbocks.com

the sharing option isn’t working properly so i will copy my code here.

Blockquote

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

int ultrafast(int n1, int n2){
vector vec;
while(n1>0 || n2>0){
int l1 = (n1&1);
int l2 = (n2&1);
int l = l1^l2;
vec.push_back(l);
n1 = n1>>1;
n2 = n2>>1;
}

reverse(vec.begin(), vec.end());
for(int i = 0; i < vec.size() ; i++){
cout<<vec[i]; 
}

return 0;
}

int main() {
int t,n1,n2;
cin>>t;
while(t–){
cin>>n1>>n2;
cout<<ultrafast(n1,n2);
}
}`

hello @shibangi your output is coming wrong because you have considered the number as an integer like number and on that you are applyin bit operations.
you know na numbers are stored in the binary represenetation.
the number 10111 is something other in the binary representation but not 10111.
you have to analyse that.
you are not extracting the digit in the number but you are doing on digits in the binary representation.
you can simply treat this as string also .
here for your reference i am attaching the code:


if you have any doubt you can ask here:
Happy Learning !!