here outdata is buffer of size[8*1024],can you tell me the exactly what will happened after execution of above lines??
-
\$\begingroup\$ A bit more background would be nice. \$\endgroup\$Djindjidj– Djindjidj2016-09-27 06:39:53 +00:00Commented Sep 27, 2016 at 6:39
-
\$\begingroup\$ I would suggest start by studying operators in Java. \$\endgroup\$wondra– wondra2016-09-27 06:55:21 +00:00Commented Sep 27, 2016 at 6:55
-
\$\begingroup\$ Please copy-paste the code, don't just insert an image of code. \$\endgroup\$Vaillancourt– Vaillancourt ♦2016-09-27 14:06:13 +00:00Commented Sep 27, 2016 at 14:06
1 Answer
Your code looks like it takes an array with rgba values in the format [R, G, B, A, R, G, B, A...] and compresses it to the [RGBA, RGBA, RGBA...] format using bitwise operations (<< and &).
The & 0xFF part is called bitmasking, it makes the last 8 bits of the number stay the same, but others are zeroed.
0000110011101110 & 0xFF -> 0000000011101110
The number + (number2 << 8) concatenates the numbers, so the first 8 bits will contain the first number, the second 8 bits will contain the second number
10101010 << 8 -> 1010101000000000
10101010 + (11101110 << 8) -> 1110111010101010
-
\$\begingroup\$ @wondra java can't do bitwise operations on anything other than integers, wich are 32 bits, so yes, it's compression \$\endgroup\$Bálint– Bálint2016-09-27 07:09:29 +00:00Commented Sep 27, 2016 at 7:09
-
\$\begingroup\$ It is very bold statement that taking 8 bits, implicitly making it 32 and then back 8 is compression. \$\endgroup\$wondra– wondra2016-09-27 07:21:42 +00:00Commented Sep 27, 2016 at 7:21
-
1\$\begingroup\$ @wondra I don't think you understood my answer. The current code takes 4 32 bit (they are originally 32 bits, they never were 8 bit) numbers (that's 128 bits), takes their last 8 bits and puts them into 1 32 bit number. \$\endgroup\$Bálint– Bálint2016-09-27 07:37:49 +00:00Commented Sep 27, 2016 at 7:37