Files
processing4/mobile/web/reference/API/bitwiseAND.xml
2005-01-27 06:48:42 +00:00

75 lines
1.7 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>&amp; (bitwise AND)</name>
<category>Math</category>
<subcategory>Bitwise Operators</subcategory>
<usage>Web &amp; Application</usage>
<example>
<image></image>
<code>
int a = 207; // In binary: 11001111
int b = 61; // In binary: 00111101
int c = a &amp; b; // In binary: 00001101
println(c); // Prints "13", the decimal equivalent to 00001101
</code>
</example>
<example>
<image></image>
<code>
color argb = color(204, 204, 51, 255);
// The sytax "&amp; 0xFF" compares the binary
// representation of the two values and
// makes all but the last 8 bits into a 0.
// "0xFF" is 00000000000000000000000011111111
int a = argb >> 24 &amp; 0xFF;
int r = argb >> 16 &amp; 0xFF;
int g = argb >> 8 &amp; 0xFF;
int b = argb &amp; 0xFF;
fill(r, g, b, a);
rect(30, 20, 55, 55);
</code>
</example>
<description>
Compares each corresponding bit in the binary representation of the values. For each comparison two 1's yeild 1, 1 and 0 yeild 0, and two 0's yeild 0. This is easy to see when we look at the binary representation of numbers<br /><br /><pre> 11010110 // 214<br />&amp; 01011100 // 92<br /> --------<br /> 01010100 // 84</pre><br />To see the binary representation of a number, use the <b>binary()</b> function with <b>println()</b>.
</description>
<syntax>
<c>value</c> &amp; <c>value2</c>
</syntax>
<parameter>
<label>value1</label>
<description>int, char, byte</description>
</parameter>
<parameter>
<label>value2</label>
<description>int, char, byte</description>
</parameter>
<returns></returns>
<related>
| (bitwise OR)
binary()
</related>
<availability>1.0</availability>
<type>Operator</type>
<partof>PDE</partof>
<level>Extended</level>
</root>