-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbitwise.html
113 lines (95 loc) · 5.73 KB
/
bitwise.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>6.6. Bitwise Functions — Presto 0.184 Documentation</title>
<link rel="stylesheet" href="../_static/presto.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.184',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Presto 0.184 Documentation" href="../index.html" />
<link rel="up" title="6. Functions and Operators" href="../functions.html" />
<link rel="next" title="6.7. Decimal Functions and Operators" href="decimal.html" />
<link rel="prev" title="6.5. Mathematical Functions and Operators" href="math.html" />
</head>
<body role="document">
<div class="header">
<h1 class="heading"><a href="../index.html">
<span>Presto 0.184 Documentation</span></a></h1>
<h2 class="heading"><span>6.6. Bitwise Functions</span></h2>
</div>
<div class="topnav">
<p class="nav">
<span class="left">
« <a href="math.html">6.5. Mathematical Functions and Operators</a>
</span>
<span class="right">
<a href="decimal.html">6.7. Decimal Functions and Operators</a> »
</span>
</p>
</div>
<div class="content">
<div class="section" id="bitwise-functions">
<h1>6.6. Bitwise Functions</h1>
<dl class="function">
<dt id="bit_count">
<code class="descname">bit_count</code><span class="sig-paren">(</span><em>x</em>, <em>bits</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Count the number of bits set in <code class="docutils literal"><span class="pre">x</span></code> (treated as <code class="docutils literal"><span class="pre">bits</span></code>-bit signed
integer) in 2’s complement representation:</p>
<div class="highlight-sql"><div class="highlight"><pre><span></span><span class="k">SELECT</span> <span class="n">bit_count</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">64</span><span class="p">);</span> <span class="c1">-- 2</span>
<span class="k">SELECT</span> <span class="n">bit_count</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span> <span class="c1">-- 2</span>
<span class="k">SELECT</span> <span class="n">bit_count</span><span class="p">(</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span> <span class="mi">64</span><span class="p">);</span> <span class="c1">-- 62</span>
<span class="k">SELECT</span> <span class="n">bit_count</span><span class="p">(</span><span class="o">-</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span> <span class="c1">-- 6</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="bitwise_and">
<code class="descname">bitwise_and</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the bitwise AND of <code class="docutils literal"><span class="pre">x</span></code> and <code class="docutils literal"><span class="pre">y</span></code> in 2’s complement representation.</p>
</dd></dl>
<dl class="function">
<dt id="bitwise_not">
<code class="descname">bitwise_not</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the bitwise NOT of <code class="docutils literal"><span class="pre">x</span></code> in 2’s complement representation.</p>
</dd></dl>
<dl class="function">
<dt id="bitwise_or">
<code class="descname">bitwise_or</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the bitwise OR of <code class="docutils literal"><span class="pre">x</span></code> and <code class="docutils literal"><span class="pre">y</span></code> in 2’s complement representation.</p>
</dd></dl>
<dl class="function">
<dt id="bitwise_xor">
<code class="descname">bitwise_xor</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the bitwise XOR of <code class="docutils literal"><span class="pre">x</span></code> and <code class="docutils literal"><span class="pre">y</span></code> in 2’s complement representation.</p>
</dd></dl>
<p>See also <a class="reference internal" href="aggregate.html#bitwise_and_agg" title="bitwise_and_agg"><code class="xref py py-func docutils literal"><span class="pre">bitwise_and_agg()</span></code></a> and <a class="reference internal" href="aggregate.html#bitwise_or_agg" title="bitwise_or_agg"><code class="xref py py-func docutils literal"><span class="pre">bitwise_or_agg()</span></code></a>.</p>
</div>
</div>
<div class="bottomnav">
<p class="nav">
<span class="left">
« <a href="math.html">6.5. Mathematical Functions and Operators</a>
</span>
<span class="right">
<a href="decimal.html">6.7. Decimal Functions and Operators</a> »
</span>
</p>
</div>
<div class="footer" role="contentinfo">
</div>
</body>
</html>