I'm new to C as a language, and I'm trying to do an XOR operation on two different data types, then store the result in a byte array at offset 1. The array is fixed, and will always be 8 bytes. I'd like to just check with all of you that I'm handling this correctly.
For background, I'd like buf
to be the result as a uint8_t
array, and my input data types are a char array and another byte array that will be constant in the application. I feel as though there's some casting that I'm missing, but I'm not sure where to look aside from asking:
#include <stdio.h>
#include <stdint.h>
int main()
{
uint8_t HANDSHAKE_SN[8] = { 0x13, 0x81, 0x22, 0x13, 0xFA, 0x32, 0x65, 0xFA };
uint8_t buf[8] = { 0x02, 0, 0, 0, 0, 0, 0, 0 };
char sn[8] = "2345678";
for(uint8_t i=1;i<9;i++)
{
buf[i] = sn[i-1] ^ HANDSHAKE_SN[i-1];
}
printf("%s",buf);
}