I am struggling with bit masking or maybe handling bit overflow.
I get data from data stream, and it is stored in char
type buffer, and I need to access particular index of the buffer. When I try so, I get unexpected results.
Something like below..
char buffer[BUFFER_SIZE];
/* ...recv from network stream performed... */
printf("buffer[index] = 0x%x\n", buffer[index]); /* => 0xFFFFFFB8 */
char dummyChar = buffer[index] & 0x000000FF;
printf("dummyChar = 0x%x\n", dummyChar); /* => 0xFFFFFFB8 */
The buffer is char
type. Why am I getting 32 bits size when I print buffer[index]?
I also masked the buffer[index]
with 0x000000FF, but I am still getting 0xFFFFFFB8. Why?
I only want to get 0xB8, can anyone tell me how? I am pretty sure it is 1 byte size..