Code: Select all
var = (16777216 * data[0]) + (65536 * data[1]) + (256 * data[2]) + data[3];
I have a good understanding of binary, i just cant understand this; even when i convert it to work with shifts and xor.
Moderator: Coders of Rage
Code: Select all
var = (16777216 * data[0]) + (65536 * data[1]) + (256 * data[2]) + data[3];
This actually helped me a lot. I just read an article regarding color depth and completely get it now.Van-B wrote:It could be a 24-bit integer converter - sometimes this is used when specifying image colours, RGBA. That could take the 4 byte size components of colour... red, green, blue, and alpha - then store them in a double word integer.
yeah... but it's not exactly the best idea... it should be shifts and OR'sVan-B wrote:It could be a 24-bit integer converter - sometimes this is used when specifying image colours, RGBA. That could take the 4 byte size components of colour... red, green, blue, and alpha - then store them in a double word integer.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Ginto8 wrote:yeah... but it's not exactly the best idea... it should be shifts and OR'sVan-B wrote:It could be a 24-bit integer converter - sometimes this is used when specifying image colours, RGBA. That could take the 4 byte size components of colour... red, green, blue, and alpha - then store them in a double word integer.
Code: Select all
#define RGBAToInt1(%0,%1,%2,%3) (((%0) << 24) | ((%1) << 16) | ((%2) << 8 | (%3)))
#define RGBAToInt2(%0,%1,%2,%3) ((16777216 * (%0)) + (65536 * (%1)) + (256 * (%2)) + (%3))
#define RGBAToInt3(%0,%1,%2,%3) ((16777216 * (%0)) | (65536 * (%1)) | (256 * (%2)) | (%3))
//10,000,000 loopings
RGBAToInt (1): Number = 946968831 || Time = 3006 ms
RGBAToInt (2): Number = 946968831 || Time = 2762 ms
RGBAToInt (3): Number = 946968831 || Time = 2894 ms
RGBAToInt (1): Number = -2070156545 || Time = 3038 ms
RGBAToInt (2): Number = -2070156545 || Time = 2764 ms
RGBAToInt (3): Number = -2070156545 || Time = 2897 ms
RGBAToInt (1): Number = 1266655999 || Time = 3029 ms
RGBAToInt (2): Number = 1266655999 || Time = 2764 ms
RGBAToInt (3): Number = 1266655999 || Time = 2900 ms
Furthermore any decent compiler (MSVC ) will turn power of two integer arithmetic into shifts.Ginto8 wrote:yeah... but it's not exactly the best idea... it should be shifts and OR'sVan-B wrote:It could be a 24-bit integer converter - sometimes this is used when specifying image colours, RGBA. That could take the 4 byte size components of colour... red, green, blue, and alpha - then store them in a double word integer.
Says the MSVC fanboy, aha jkqpHalcy0n wrote:Furthermore any decent compiler (MSVC ) will turn power of two integer arithmetic into shifts.Ginto8 wrote:yeah... but it's not exactly the best idea... it should be shifts and OR'sVan-B wrote:It could be a 24-bit integer converter - sometimes this is used when specifying image colours, RGBA. That could take the 4 byte size components of colour... red, green, blue, and alpha - then store them in a double word integer.
Kyosaur wrote:Here are the results:
#1: I'm pretty sure g++ does that (but since I have minimal knowledge about compilers, don't quote me)qpHalcy0n wrote:Furthermore any decent compiler (MSVC ) will turn power of two integer arithmetic into shifts.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.