02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

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.

Chapter 7: So what is a variable?<br />

Binary numbers<br />

These numbers use only the symbols 1 and 0. The value of the first column (furthest <strong>to</strong> the right) is<br />

1, the second column is 2, the third is 4. Each column is double the previous. Therefore the binary<br />

representation of 10 and 7 are<br />

1010 (8 + 0 + 2 + 0)<br />

0111 (0 + 4 + 2 + 1)<br />

|(Or) opera<strong>to</strong>r<br />

This combines the bits that make up the number. If either bit is set then the resulting bit is set.<br />

1010 Or’ed with 0111 gives 1111 which is 8 + 4 + 2 + 1or15.<br />

&(And) opera<strong>to</strong>r<br />

This combines the bits that make up the number. If both bits are set then the resulting bit is set.<br />

1010 And’ed with 0111 gives 0010, which is 0 + 0 + 2 + 0, or 2.<br />

∧ (Xor) opera<strong>to</strong>r<br />

This combines the bits that make up the number. If one bit is set but not both then the resulting<br />

bit is set.<br />

1010 Xor’ed with 0111 gives 1101, which is 8 + 4 + 0 + 1or13.<br />

≪(left shift) opera<strong>to</strong>r<br />

This moves the bits that make up the number.<br />

1010 left shifted 7 places gives 10100000000 or 1024 + 0 + 256 or 1280.<br />

≫(right shift) opera<strong>to</strong>r<br />

This moves the bits that make up the number.<br />

1010 right shifted 7 places gives 0000, the bits are left <strong>to</strong> zero after shifting only 4 places so<br />

7 still leaves the result as zero.<br />

All the opera<strong>to</strong>rs that include the equals sign simply do the same but assign the result <strong>to</strong> the<br />

variable on the left. ‘Examples/Chapter07/Variables03.fla’ shows all these opera<strong>to</strong>rs in action. For<br />

most programs in the book we will just be using the simple arithmetic opera<strong>to</strong>rs but it is useful <strong>to</strong><br />

know how they all work.<br />

89

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

Saved successfully!

Ooh no, something went wrong!