I found this line of code: this.red = (float)(par4 >> 16 & 255) / 255.0F;
where red has been declared as a float
.
I am trying to understand what it does, especially because the full code is:
this.red = (float)(par4 >> 16 & 255) / 255.0F;
this.blue = (float)(par4 >> 8 & 255) / 255.0F;
this.green = (float)(par4 & 255) / 255.0F;
this.alpha = (float)(par4 >> 24 & 255) / 255.0F;
GL11.glColor4f(this.red, this.blue, this.green, this.alpha);
so I'm guessing this somehow uses different locations of an int (par4
) to color text. par4
is equal to 553648127
in this case.
What do those four lines mean, notably the >> 16 & 25
?
RGB with alpha channel (usually known as RGBA or aRGB) are four bytes packed into one integer.
AAAAAAAARRRRRRRRBBBBBBBBGGGGGGGG // the original par4, each char represents one bit.
// where ARBG stands for alpha, red, blue and green bit.
The shift and and operator are used to retrieve each individual byte. For example, par4 >> 16 & 255
is first right-shifting the integer 16 bits such that the original 3rd byte is located at base, and the 255
is served as mask to extract only one byte.
And par4 >> 16
will right-shift the original byte 16 bits;
0000000000000000AAAAAAAARRRRRRRR
Finally, applying &255
, which is 00000000000000000000000011111111
in bit-representation, will mask the last 8 bits:
0000000000000000AAAAAAAARRRRRRRR
& 00000000000000000000000011111111
= 000000000000000000000000RRRRRRRR
This gives you the red byte.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With