mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 18:10:43 +01:00
78 lines
2.1 KiB
XML
78 lines
2.1 KiB
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
<root>
|
|
<name><< (left shift)</name>
|
|
|
|
<category>Math</category>
|
|
|
|
<subcategory>Bitwise Operators</subcategory>
|
|
|
|
<usage>Web & Application</usage>
|
|
|
|
<example>
|
|
<image></image>
|
|
<code>
|
|
int m = 1 << 3; // In binary: 1 to 1000
|
|
println(m); // Prints "8"
|
|
int n = 1 << 8; // In binary: 1 to 100000000
|
|
println(n); // Prints "256"
|
|
int o = 2 << 3; // In binary: 10 to 10000
|
|
println(o); // Prints "16"
|
|
int p = 13 << 1; // In binary: 1101 to 11010
|
|
println(p); // Prints "26"
|
|
</code>
|
|
</example>
|
|
|
|
<example>
|
|
<image></image>
|
|
<code>
|
|
// Packs four 8 bit numbers into one 32 bit number
|
|
int a = 255; // Binary: 00000000000000000000000011111111
|
|
int r = 204; // Binary: 00000000000000000000000011001100
|
|
int g = 204; // Binary: 00000000000000000000000011001100
|
|
int b = 51; // Binary: 00000000000000000000000000110011
|
|
a = a << 24; // Binary: 11111111000000000000000000000000
|
|
r = r << 16; // Binary: 00000000110011000000000000000000
|
|
g = g << 8; // Binary: 00000000000000001100110000000000
|
|
|
|
// Equivalent to "color argb = color(r, g, b, a)" but faster
|
|
color argb = a | r | g | b;
|
|
fill(argb);
|
|
rect(30, 20, 55, 55);
|
|
</code>
|
|
</example>
|
|
|
|
<description>
|
|
Shifts bits to the left. The number to the left of the operator is shifted the number of places specified by the number to the right. Each shift to the left doubles the number, therefore each left shift multiplies the original number by 2. Use the left shift for fast multiplication or to pack a group of numbers together into one larger number. Left shifting only works with integers or numbers which automatically convert to an integer such at byte and char.
|
|
</description>
|
|
|
|
<syntax>
|
|
<c>value</c> << <c>n</c>
|
|
</syntax>
|
|
|
|
<parameter>
|
|
<label>value</label>
|
|
<description>int: the value to shift</description>
|
|
</parameter>
|
|
|
|
<parameter>
|
|
<label>n</label>
|
|
<description>int: the number of places to shift left</description>
|
|
</parameter>
|
|
|
|
<returns></returns>
|
|
|
|
<related>
|
|
>> (right shift)
|
|
</related>
|
|
|
|
<availability>1.0</availability>
|
|
|
|
<type>Operator</type>
|
|
|
|
<partof>PDE</partof>
|
|
|
|
<level>Extended</level>
|
|
|
|
|
|
</root>
|