<lineannotation>\x04d2</lineannotation>
cast(1234 as bytea) <lineannotation>\x000004d2</lineannotation>
cast(-1234 as bytea) <lineannotation>\xfffffb2e</lineannotation>
'\x8000'::bytea::smallint <lineannotation>-32768</lineannotation>
'\x8000'::bytea::integer <lineannotation>32768</lineannotation>
</programlisting>
Casting a <type>bytea</type> to an integer will raise an error if the
length of the <type>bytea</type> exceeds the width of the integer type.
</para>
<para>
See also the aggregate function <function>string_agg</function> in
<xref linkend="functions-aggregate"/> and the large object functions
in <xref linkend="lo-funcs"/>.
</para>
</sect1>
<sect1 id="functions-bitstring">
<title>Bit String Functions and Operators</title>
<indexterm zone="functions-bitstring">
<primary>bit strings</primary>
<secondary>functions</secondary>
</indexterm>
<para>
This section describes functions and operators for examining and
manipulating bit strings, that is values of the types
<type>bit</type> and <type>bit varying</type>. (While only
type <type>bit</type> is mentioned in these tables, values of
type <type>bit varying</type> can be used interchangeably.)
Bit strings support the usual comparison operators shown in
<xref linkend="functions-comparison-op-table"/>, as well as the
operators shown in <xref linkend="functions-bit-string-op-table"/>.
</para>
<table id="functions-bit-string-op-table">
<title>Bit String Operators</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Operator
</para>
<para>
Description
</para>
<para>
Example(s)
</para></entry>
</row>
</thead>
<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>bit</type> <literal>||</literal> <type>bit</type>
<returnvalue>bit</returnvalue>
</para>
<para>
Concatenation
</para>
<para>
<literal>B'10001' || B'011'</literal>
<returnvalue>10001011</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>bit</type> <literal>&</literal> <type>bit</type>
<returnvalue>bit</returnvalue>
</para>
<para>
Bitwise AND (inputs must be of equal length)
</para>
<para>
<literal>B'10001' & B'01101'</literal>
<returnvalue>00001</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>bit</type> <literal>|</literal> <type>bit</type>
<returnvalue>bit</returnvalue>
</para>
<para>
Bitwise OR (inputs must be of equal length)
</para>
<para>
<literal>B'10001' | B'01101'</literal>
<returnvalue>11101</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>bit</type> <literal>#</literal> <type>bit</type>
<returnvalue>bit</returnvalue>
</para>
<para>
Bitwise exclusive OR (inputs must be of equal length)
</para>
<para>
<literal>B'10001' # B'01101'</literal>
<returnvalue>11100</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<literal>~</literal> <type>bit</type>
<returnvalue>bit</returnvalue>
</para>
<para>
Bitwise NOT
</para>
<para>
<literal>~ B'10001'</literal>
<returnvalue>01110</returnvalue>
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<type>bit</type> <literal><<</literal>