0

I'm doing this Princeton challenge and I encountered a line I don't understand on the following page http://www.cs.princeton.edu/courses/archive/fall10/cos126/assignments/lfsr.html, the line is just below the first picture of the pipe.

For each pixel (x, y), in the order (0, 0), (0, 1), (0, 2), ..., extract the red, green, and blue components of the color (each component is an integer between 0 and 255).

Then, xor the red component with 8 newly generated bits. Do the same for the green (using another 8 newly generated bits) and, finally, the blue.

Create a new color using the result of the xor operations, and set the pixel to that color.

I'm not quite sure how a new color can be created after 3 xor operations, since an xor operation would only yield a true or false value.

Community
  • 1
  • 1
nope
  • 223
  • 4
  • 15

6 Answers6

7

No, you're xoring an 8-bit color component value with another 8-bit value, along the lines of:

    1010 1010
xor 1111 0000
    ---- ----
    0101 1010

While a single xor operates on a two bits to produce another bit, doing that operation on multi-bit values means doing it on each bit in turn.

See also this answer.

Community
  • 1
  • 1
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

An xor in boolean (logical) operations returns only true or false, but you can use a bitwise xor too. In that case, each bit in a number (an 8 bit value in this case) is treated as if it were a boolean. This results in 8 new bits being either true or false, thus returning a new 8 bit value. Three of these combined will give you an rgb value.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
0

I think it's bitwise XOR, you convert the color to binary, then XOR each digit to get the result. For example 00001111 XOR 11111111 = 11110000

Kien Truong
  • 11,179
  • 2
  • 30
  • 36
0

since an xor operation would only yield a true or false value.

your statement is untrue. for example:

1110 xor 1001 = 0111

for more information see:http://en.wikipedia.org/wiki/Bitwise_operation#XOR

Yasser Souri
  • 1,967
  • 2
  • 19
  • 26
0

I'm not quite sure how a new color can be created after 3 xor operations, since an xor operation would only yield a true or false value.

In this case the xor operates bits by bits. So the result it's 1 or 0 but for each single bit.

1111 1111 xor

1010 1010 =

0101 0101

Heisenbug
  • 38,762
  • 28
  • 132
  • 190
0

The assignment is referring to bitwise operations.

ChrisWue
  • 18,612
  • 4
  • 58
  • 83