c - On a little-endian machine, how will bit operators work? -
i have following code takes pixel values file. on intel macbook running os x. believe little-endian. have following code using determine if least significant bit set on pixels. compiles , runs, not sure if operations giving me correct data.
typedef struct { unsigned char blue; unsigned char green; unsigned char red; } pixel_t; pixel_t *pixels = malloc(((bmp->dib.bmp_bytesz/3)+1) * sizeof(*pixels)); printf("%u", (pixels[i].red & 0x01)); printf("%u", (pixels[i].green & 0x01)); printf("%u", (pixels[i].blue & 0x01));
little-endian , big-endian refers order of bytes (not bits, per se) in larger units (like short
or int
).
the bitwise operations same; operations giving least significant bit of numbers in pixels[i].blue
etc. if stored in char
(or unsigned char
or signed char
), there no issue. if stored in int
or short
or something, byte being addressed different depending on whether machine big-endian or little-endian, still least significant bit of number on platform.
Comments
Post a Comment