Bitwise XOR using two strings in C | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Bitwise XOR using two strings in C

rem and key are char array containing 1011 and 1101 respectively. for(j=0;j<length;j++)    { rem[j]=((rem[j])^(key[j])); } After execution of the above code using XOR, infinite loop occurs for(j=0;j<length;j++) { rem[j]=( (rem[j])^(key[j]) )+'0'; } But if I add '0' it gives me the correct output So why does the code work with the +'0' ?

6th Apr 2021, 7:59 AM
Merlyn J
1 Answer
0
Maybe the XOR operation is returning an int value which is making the comparison invalid in the first loop To avoid this in your second loop the int value is converted to s char by adding character zero Maybe you can look up to some documentation on coversion between char and int ... And try to print the value of XOR operation to see what it is actually returning...
6th Apr 2021, 10:07 PM
AzmayenSabil
AzmayenSabil - avatar