Hello all, I'm pretty new to C, so this might be a silly question. Im doing some bitshifting in chunks of 8 bytes and outputting 7 bytes. For the output im using a char array of size 7 storing a single byte in each location. Here's where things deviate from what I expect: when I print the values at all 7 locations of my char array in hex, I get 32 bit results form each array index (which should only be ably to hold 8 bits). Why is this? Heres my relevant (and probably poorly formatted) code:
Edit: buff[] is a char array as well, declared earlier in the code. The values it outputs are correct.
Code:
char out[7];
out[0] = ((buff[i] & 0x7f) << 1) | ((buff[i+1] & 0x40) >> 6);
printf("%x -> %x\n",buff[i],out[0]);
out[1] = ((buff[i+1] & 0x3f) << 2) | ((buff[i+2] & 0x60) >> 5);
printf("%x -> %x\n",buff[i+1],out[1]);
out[2] = ((buff[i+2] & 0x1f) << 3) | ((buff[i+3] & 0x70) >> 4);
printf("%x -> %x\n",buff[i+2],out[2]);
out[3] = ((buff[i+3] & 0x0f) << 4) | ((buff[i+4] & 0x78) >> 3);
printf("%x -> %x\n",buff[i+3],out[3]);
out[4] = ((buff[i+4] & 0x07) << 5) | ((buff[i+5] & 0x7c) >> 2);
printf("%x -> %x\n",buff[i+4],out[4]);
out[5] = ((buff[i+5] & 0x03) << 6) | ((buff[i+6] & 0x7e) >> 1);
printf("%x -> %x\n",buff[i+5],out[5]);
out[6] = ((buff[i+6] & 0x01) << 7) | (buff[i+7] & 0x7f);
printf("%x -> %x\n",buff[i+6],out[6]);
Heres some sample output
hex on right is orig val from buff[] index hex on left is val of out[] index:
61 -> ffffffc362 -> ffffff8b
63 -> 1e
64 -> 4c
65 -> ffffffb9
66 -> ffffffb3
67 -> ffffffe8
Why are the values on the right hand side 32 bits when each one should only represent a char (1 byte) and both are printed using hex %x?