:meta-keywords: CUBRID bitwise operator, cubrid bit_and, cubrid bit_or, cubrid bit_xor, cubrid bit_count
:meta-description: A Bitwise operator performs operations in bits, and can be used in arithmetic operations.
:tocdepth: 3
***************************
BIT Functions and Operators
***************************
.. contents::
Bitwise Operator
================
A **Bitwise** operator performs operations in bits, and can be used in arithmetic operations. An integer type is specified as the operand and the **BIT** type cannot be specified. An integer of **BIGINT** type (64-bit integer) is returned as a result of the operation. If one or more operands are **NULL**, **NULL** is returned.
The following table shows the bitwise operators supported by CUBRID.
**The bitwise operators**
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
| Bitwise operator | Description | Expression | Return Value |
+======================+================================================================================================================================================+================+================+
| & | Performs AND operation in bits and returns a BIGINT integer. | 17 & 3 | 1 |
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
| \| | Performs OR operation in bits and returns a BIGINT integer. | 17 \| 3 | 19 |
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
| ^ | Performs XOR operation in bits and returns a BIGINT integer. | 17 ^ 3 | 18 |
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
| ~ | A unary operator. It performs complementary operation that reverses (INVERT) the bit order of the operand and returns a BIGINT integer. | ~17 | -18 |
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
| << | Performs the operation to shift bits of the left operand as far to the left as the value of the right operand, and returns a BIGINT integer. | 17 << 3 | 136 |
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
| >> | Performs the operation to shift bits of the left operand as far to the right as the value of the right operand, and returns a BIGINT integer. | 17 >> 3 | 2 |
+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+
BIT_AND
=======
.. function:: BIT_AND (expr)
As an aggregate function, it performs **AND** operations in bits on every bit of *expr*. The return value is a **BIGINT** type. If there is no row that satisfies the expression, **NULL** is returned.
:param expr: An expression of integer type
:rtype: BIGINT
.. code-block:: sql
CREATE TABLE bit_tbl(id int);
INSERT INTO bit_tbl VALUES (1), (2), (3), (4), (5);
SELECT 1&3&5, BIT_AND(id) FROM bit_tbl WHERE id in(1,3,5);
::
1&3&5 bit_and(id)
============================================
1 1
BIT_OR
======
.. function:: BIT_OR (expr)
As an aggregate function, it performs **OR** operations in bits on every bit of *expr*. The return value is a **BIGINT** type. If there is no row that satisfies the expression, **NULL** is returned.
:param expr: An expression of integer type
:rtype: BIGINT
.. code-block:: sql
SELECT 1|3|5, BIT_OR(id) FROM bit_tbl WHERE id in(1,3,5);
::
1|3|5 bit_or(id)
============================================
7 7
BIT_XOR
=======
.. function:: BIT_XOR (expr)
As an aggregate function, it performs **XOR** operations in bits on every bit of *expr*. The return value is a **BIGINT** type. If there is no row that satisfies the expression, **NULL** is returned.
:param expr: An expression of integer type
:rtype: BIGINT
.. code-block:: sql
SELECT 1^2^3, BIT_XOR(id) FROM bit_tbl WHERE id in(1,3,5);
::
1^3^5 bit_xor(id)
============================================
7 7
BIT_COUNT
=========
.. function:: BIT_COUNT (expr)
The **BIT_COUNT** function returns the number of bits of *expr* that have been set to 1; it is not an aggregate function. The return value is a **BIGINT** type.
:param expr: An expression of integer type
:rtype: BIGINT
.. code-block:: sql
SELECT BIT_COUNT(id) FROM bit_tbl WHERE id in(1,3,5);
::
bit_count(id)
================
1
2
2
"I can't think of it," replied Frank; "what is it?" Judy Abbott Still the tonga; uphill and down, over the hilly country, with a horizon of dull, low mountains, and the horses worse and worse, impossible to start but by a storm of blows. Towards evening a particularly vicious pair ended by overturning us into a ditch full of liquid mud. The sais alone was completely immersed, and appealed loudly to Rama with shrieks of terror. Abibulla on his part, after making sure that the sahibs and baggage were all safe and sound, took off his shoes, spread his dhoti on the ground, and made the introductory salaams of thanksgiving to the Prophet, while the coolie driver returned thanks to Rama. "Did the girl know her own story?" she asked. "Nonsense—you're coming wud me." "I'm afraid father forgets things. But come in, he's bound to be home to his dinner soon." HoME香港一级高清仑片
ENTER NUMBET 0018www.yangmeijiu.com.cn
www.hongxingsumo.com.cn
dunxuanfeng.com.cn
sgcn77mx.com.cn
www.scdehui.com.cn
www.ealey.com.cn
ctww418.com.cn
ivpe.com.cn
www.gdbhsw.com.cn
tlbus.com.cn