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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

764<br />

(expressed as 1000000 in binary) has its bits shifted 1 place to the right, using the expression<br />

64 >> 1, then the binary result will be 100000, which equals 32 in decimal (2 6 ).<br />

It’s no coincidence that shifting to the right 1 bit halved the number. In fact, this is an<br />

excellent use for bit shifting. As you might suspect, shifting to the left 1 bit doubles the<br />

number. Here’s a simple example in <strong>Processing</strong> that outputs some results verifying this:<br />

int val1 = 1000;<br />

int val2 = 32044;<br />

int val3 = -2275686;<br />

println("val1 = " + val1);<br />

println("val1 >> 1 = " + (val1>>1));<br />

println("val1 > 1 = " + (val2>>1));<br />

println("val2 > 1 = " + (val3>>1));<br />

println("val3

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

Saved successfully!

Ooh no, something went wrong!