-7
\$\begingroup\$

enter image description herehere outdata is buffer of size[8*1024],can you tell me the exactly what will happened after execution of above lines??

\$\endgroup\$
3
  • \$\begingroup\$ A bit more background would be nice. \$\endgroup\$
    – Djindjidj
    Sep 27, 2016 at 6:39
  • \$\begingroup\$ I would suggest start by studying operators in Java. \$\endgroup\$
    – wondra
    Sep 27, 2016 at 6:55
  • \$\begingroup\$ Please copy-paste the code, don't just insert an image of code. \$\endgroup\$
    – Vaillancourt
    Sep 27, 2016 at 14:06

1 Answer 1

1
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\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
    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
    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
    Sep 27, 2016 at 7:37

Not the answer you're looking for? Browse other questions tagged .