After managing to correctly execute xor of chars between "$" and "*" I need to perform "IF statement" to check if the xor indeed equals "64". I need to merge these two chars and somehow compare to the xor. The problem is i variables type. XOR (sumcheck) is in hex, the b (merging of 6 and 4) is in dec. Should i convert XOR to dec value, or convert 64(dec) to 64(hex) value?
#include <stdio.h>
int main(void) {
int i;
int xor = 0;
int b;
// $GPGLL,,,,,,V,N*64
char Received[18]= {'$','G','P','G','L','L',',',',',',',',',',',',','V',',','N','*','6','4'};
int loop;
// display array
//for(loop = 0; loop < 18; loop++)
// printf("%c ", Received[loop]);
for(int i = 1; i<=14; i++)
xor ^= Received[i];
printf("%#02x ", xor);
printf("%d ", xor);
b = ((Received[16]-'0') *10) + Received[17]-'0';
printf("%d ", b);
if(xor == b){
printf("WORKING!");
}
else{
printf("not working");
}
return 0;
}
printf("%#02x ", xor, "%d ", xor);it should beprintf("%#02x %d\n", xor, xor);