I have two char arrays A and B. I want to perform bitwise xor on these two arrays. But the output shows a garbage value. Where am I going wrong?
I tried typecasting the output in char since array A and array B contains 0 and 1 in ASCII.But it didn't work.
#include<iostream> #include<cstdlib> using namespace std; int main(){ char A[4] = {0,1,1,0}; char B[4] = {1,1,1,0}; char XOR[4]; cout<< " PRINTING "<<endl; for(int i =0; i<4; i++) { XOR[i] = (char)(A[i]^B[i]); cout<<(char)XOR[i]; } cout<<endl; } Expected output is 1000, but the output I get is a garbage.
int.XOR[i]'s type is alreadychar. Casting it tocharisn't doing anything.charis printed as ASCII char, not integer". If you can find a better duplicate let me know though, I'm sure there are at least 10 more. And with the answers here we got yet another duplicate.