Nov 3, 2009 at 4:56pm UTC
Good day! Im a C++ beginner, can anybody explain to me how this 2 codes work?
#define _RGB16BIT565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))
#define _RGB32BIT(a,r,g,b) ( + ((g) << 8) + ((r) << 16) + ( << 24))
Nov 3, 2009 at 5:49pm UTC
#define _RGB16BIT565(r,g,b)
is defining a macro called _RGB16BIT565 with three parameters
The second part is some mathematical trick:
Last edited on Nov 3, 2009 at 5:51pm UTC
Nov 3, 2009 at 5:55pm UTC
Strange though - I thought the top one should be ((g%64) << 5) not ((g%64) << 6)
Last edited on Nov 3, 2009 at 8:58pm UTC
Nov 3, 2009 at 6:37pm UTC
Thanks for clearing that up for me. However im having problem understanding the parenthesis for example:
#define _RGB16BIT565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))
some opening parenthesis has no closing parenthesis which i think will give error but it didn't. Hows this syntax possible? Is creating a macro different?