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

72 lines
1.7 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>| (bitwise OR)</name>
<category>Math</category>
<subcategory>Bitwise Operators</subcategory>
<usage>Web &amp; Application</usage>
<example>
<image></image>
<code>
int a = 205; // In binary: 11001101
int b = 45; // In binary: 00101101
int c = a | b; // In binary: 11101101
println(c); // Prints "237", the decimal equivalent to 11101101
</code>
</example>
<example>
<image></image>
<code>
int a = 255 &lt;&lt; 24; // Binary: 11111111000000000000000000000000
int r = 204 &lt;&lt; 16; // Binary: 00000000110011000000000000000000
int g = 204 &lt;&lt; 8; // Binary 00000000000000001100110000000000
int b = 51; // Binary: 00000000000000000000000000110011
// OR the values together: 11111111110011001100110000110011
color argb = a | r | g | b;
fill(argb);
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 1, 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 /> 11011110 // 222</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> | <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>
&amp; (bitwise AND)
binary()
</related>
<availability>1.0</availability>
<type>Operator</type>
<partof>PDE</partof>
<level>Extended</level>
</root>