04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

768<br />

Here is the operation expressed in base 2 (remember, only when both parallel bits are 1 is<br />

the result 1; otherwise it’s 0):<br />

100<br />

& 110<br />

100<br />

Surprisingly, this result is still 4 when you convert it back to base 10. Pretty odd, huh?<br />

Here’s an example that compares the parallel bits of the binary values of 126 <strong>and</strong> 3498,<br />

again using the bitwise AND operator:<br />

And here’s the operation expressed in base 2:<br />

000001111110<br />

& 110110101010<br />

000000101010<br />

The simplifies to 101010 if zeros on the left are removed.<br />

While adding zeros to the left of the number has no effect, adding zeros to<br />

the right of a binary number will change the value, so don’t do it.<br />

| is the bitwise OR operator, also called inclusive OR. It operates by evaluating whether<br />

either of the two parallel bits is a one, in which case it evaluates to a one; otherwise the<br />

result is a zero. (You can also think about this as two parallel zeros equals a zero.)<br />

This next example compares the parallel bits of 4 <strong>and</strong> 6 using the OR operator:<br />

And here’s the operation expressed in base 2:<br />

100<br />

| 110<br />

110 = 6<br />

This example compares the parallel bits of the binary values of 126 <strong>and</strong> 3498, again using<br />

the bitwise OR operator:<br />

And here’s the operation expressed in base 2:<br />

000001111110<br />

| 110110101010<br />

110111111110

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!