Log in or register to post comments

please explain these lines of code

December 18, 2011 - 7:13am #1

The following lines are from texture.java file of Imagetargets sample. (line no 56 onwards..)

for (int p = 0; p {
int colour = data[p];
dataBytes[p * 4] = (byte)(colour >>> 16); // R
dataBytes[p * 4 + 1] = (byte)(colour >>> 8); // G
dataBytes[p * 4 + 2] = (byte) colour; // B
dataBytes[p * 4 + 3] = (byte)(colour >>> 24); // A
}

what does these codes do? >>> operator stands for what purpose and what calculations are done in these codes

Re: please explain these lines of code

December 19, 2011 - 3:16am #2

FYI, >> and >> is the 'bit-shift right with zero-fill' operator: the bits in a 32-bit integer are shifted right and zeroes are added on the left side.

The code unpacks color information that is in a 32-bit value (called 'colour'), rearranges the components, and stores the result in an entry in the dataBytes array.

Log in or register to post comments