-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathrightshift.xml
More file actions
executable file
·74 lines (57 loc) · 2.19 KB
/
rightshift.xml
File metadata and controls
executable file
·74 lines (57 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>>> (right shift)</name>
<category>Math</category>
<subcategory>Bitwise Operators</subcategory>
<usage>Web & Application</usage>
<example>
<image></image>
<code><![CDATA[
int m = 8 >> 3; // In binary: 1000 to 1
println(m); // Prints "1"
int n = 256 >> 6; // In binary: 100000000 to 100
println(n); // Prints "4"
int o = 16 >> 3; // In binary: 10000 to 10
println(o); // Prints "2"
int p = 26 >> 1; // In binary: 11010 to 1101
println(p); // Prints "13"
]]></code>
</example>
<example>
<image></image>
<code><![CDATA[
// Using "right shift" as a faster technique than red(), green(), and blue()
color argb = color(204, 204, 51, 255);
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF; // Faster way of getting red(argb)
int g = (argb >> 8) & 0xFF; // Faster way of getting green(argb)
int b = argb & 0xFF; // Faster way of getting blue(argb)
fill(r, g, b, a);
rect(30, 20, 55, 55);
]]></code>
</example>
<description><![CDATA[
Shifts bits to the right. 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 right halves the number, therefore each right shift divides the original number by 2. Use the right shift for fast divisions or to extract an individual number from a packed number. Right shifting only works with integers or numbers which automatically convert to an integer such at byte and char.
<br /> <br />
Bit shifting is helpful when using the <b>color</b> data type. A right shift can extract red, green, blue, and alpha values from a color. A left shift can be used to quickly reassemble a color value (more quickly than the <b>color()</b> function).
]]></description>
<syntax>
<c>value</c> >> <c>n</c>
</syntax>
<parameter>
<label>value</label>
<description><![CDATA[int: the value to shift]]></description>
</parameter>
<parameter>
<label>n</label>
<description><![CDATA[int: the number of places to shift right]]></description>
</parameter>
<returns></returns>
<related>
<< (left shift)
</related>
<availability>1.0</availability>
<type>Operator</type>
<partof>PDE</partof>
<level>Extended</level>
</root>