gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
6.7KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!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>9.6. Bit String Functions and Operators</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="functions-binarystring.html" title="9.5. Binary String Functions and Operators" /><link rel="next" href="functions-matching.html" title="9.7. Pattern Matching" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.6. Bit String Functions and Operators</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-binarystring.html" title="9.5. Binary String Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-matching.html" title="9.7. Pattern Matching">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-BITSTRING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.6. Bit String Functions and Operators</h2></div></div></div><a id="id-1.5.8.11.2" class="indexterm"></a><p>
  3. This section describes functions and operators for examining and
  4. manipulating bit strings, that is values of the types
  5. <code class="type">bit</code> and <code class="type">bit varying</code>. Aside from the
  6. usual comparison operators, the operators
  7. shown in <a class="xref" href="functions-bitstring.html#FUNCTIONS-BIT-STRING-OP-TABLE" title="Table 9.14. Bit String Operators">Table 9.14</a> can be used.
  8. Bit string operands of <code class="literal">&amp;</code>, <code class="literal">|</code>,
  9. and <code class="literal">#</code> must be of equal length. When bit
  10. shifting, the original length of the string is preserved, as shown
  11. in the examples.
  12. </p><div class="table" id="FUNCTIONS-BIT-STRING-OP-TABLE"><p class="title"><strong>Table 9.14. Bit String Operators</strong></p><div class="table-contents"><table class="table" summary="Bit String Operators" border="1"><colgroup><col /><col /><col /><col /></colgroup><thead><tr><th>Operator</th><th>Description</th><th>Example</th><th>Result</th></tr></thead><tbody><tr><td> <code class="literal">||</code> </td><td>concatenation</td><td><code class="literal">B'10001' || B'011'</code></td><td><code class="literal">10001011</code></td></tr><tr><td> <code class="literal">&amp;</code> </td><td>bitwise AND</td><td><code class="literal">B'10001' &amp; B'01101'</code></td><td><code class="literal">00001</code></td></tr><tr><td> <code class="literal">|</code> </td><td>bitwise OR</td><td><code class="literal">B'10001' | B'01101'</code></td><td><code class="literal">11101</code></td></tr><tr><td> <code class="literal">#</code> </td><td>bitwise XOR</td><td><code class="literal">B'10001' # B'01101'</code></td><td><code class="literal">11100</code></td></tr><tr><td> <code class="literal">~</code> </td><td>bitwise NOT</td><td><code class="literal">~ B'10001'</code></td><td><code class="literal">01110</code></td></tr><tr><td> <code class="literal">&lt;&lt;</code> </td><td>bitwise shift left</td><td><code class="literal">B'10001' &lt;&lt; 3</code></td><td><code class="literal">01000</code></td></tr><tr><td> <code class="literal">&gt;&gt;</code> </td><td>bitwise shift right</td><td><code class="literal">B'10001' &gt;&gt; 2</code></td><td><code class="literal">00100</code></td></tr></tbody></table></div></div><br class="table-break" /><p>
  13. The following <acronym class="acronym">SQL</acronym>-standard functions work on bit
  14. strings as well as character strings:
  15. <code class="literal"><code class="function">length</code></code>,
  16. <code class="literal"><code class="function">bit_length</code></code>,
  17. <code class="literal"><code class="function">octet_length</code></code>,
  18. <code class="literal"><code class="function">position</code></code>,
  19. <code class="literal"><code class="function">substring</code></code>,
  20. <code class="literal"><code class="function">overlay</code></code>.
  21. </p><p>
  22. The following functions work on bit strings as well as binary
  23. strings:
  24. <code class="literal"><code class="function">get_bit</code></code>,
  25. <code class="literal"><code class="function">set_bit</code></code>.
  26. When working with a bit string, these functions number the first
  27. (leftmost) bit of the string as bit 0.
  28. </p><p>
  29. In addition, it is possible to cast integral values to and from type
  30. <code class="type">bit</code>.
  31. Some examples:
  32. </p><pre class="programlisting">
  33. 44::bit(10) <em class="lineannotation"><span class="lineannotation">0000101100</span></em>
  34. 44::bit(3) <em class="lineannotation"><span class="lineannotation">100</span></em>
  35. cast(-44 as bit(12)) <em class="lineannotation"><span class="lineannotation">111111010100</span></em>
  36. '1110'::bit(4)::integer <em class="lineannotation"><span class="lineannotation">14</span></em>
  37. </pre><p>
  38. Note that casting to just <span class="quote">“<span class="quote">bit</span>”</span> means casting to
  39. <code class="literal">bit(1)</code>, and so will deliver only the least significant
  40. bit of the integer.
  41. </p><div class="note"><h3 class="title">Note</h3><p>
  42. Casting an integer to <code class="type">bit(n)</code> copies the rightmost
  43. <code class="literal">n</code> bits. Casting an integer to a bit string width wider
  44. than the integer itself will sign-extend on the left.
  45. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-binarystring.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-matching.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.5. Binary String Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.7. Pattern Matching</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1