[SDL] Get pixel value

Kylotan kylotan at kylotan.eidosnet.co.uk
Sat Aug 25 18:32:00 PDT 2001


> But what is the meaning of the following? (Supposing little endian)
> case 3: return p[0] | p[1] << 8 | p[2] << 16;

It's pretty simple really. It's just the first byte at 'p', ORed with
the 2nd byte shifted left 8 bits, ORed with the 3rd byte shifted left 16
bits. This combines the 3 bytes into a 24-bit space. Technically it
could be addition instead of OR, since all the bytes are being ORed with
zero.

Example:
p[0] = 10101010
p[1] = 11110000
p[2] = 00001111

This becomes
000011111111000010101010
which is
00001111 11110000 10101010
(ordered with p[2] on the left through to p[0] on the right).

This is returned as a Uint32, so there will be leading zeros... the
result for this example therefore would be:
00000000000011111111000010101010 (with 8 leading zeros added)

--
Ben Sizer





More information about the SDL mailing list