Q:

Extra 0xFFFFFF during xor encryption

I have this piece of code here
#include<stdio.h>

#define LEN 10

char buf[] = {0xff,0xaa,0xfc,0xe8,0x89,0x00,0x00,0x00,0x60,0x89};
char key[] = "SAMPLE KEY";

int main()
{
        int i;
        char enc[LEN];
        for(i=0;i<LEN;i++)
        {
                enc[i] = (key[i % LEN] ^ buf[i]);
                printf("0x%x,",enc[i]);
        }
}

Which outputs
OUTPUT
0xffffffac,0xffffffeb,0xffffffb1,0xffffffb8,0xffffffc5,0x45,0x20,0x4b,0x25,0xffffffd0

where the expected output is
0xac,0xeb,0xb1,0xb8,0xc5,0x45,0x20,0x4b,0x25,0xd0,

How can I fix this ?
Why does this happen ?

A:

Change buf and enc type at declaration from char to unsigned char.
It is implementation-defined whether char is a signed or unsigned type and in your implementation it is apparently a signed type.

