Suppose I have a pointer to image data which has 3 channels (RGB), 8 bits per channel and I want to display the value of a pixel like #000000, which is a 24 bit number. The data is stored like RGB RGB RGB … so I really need to read the first three bytes.
typedef unsigned char uchar;
uchar* data = get_image_data_somehow();
Maybe it’s easier than I think, but if I had four bytes, I could do something like
uint32 value = *((uint32*) data);
printf("Value is %x", value);
How is that to be done? In principle I need the 32 bit one, and fill the leading 8 bits with zero.
(assuming you’re on a Little-Endian machine)