Bitwise Functions
Vector bitwise functions operate only on IPV4 and IPV6 addresses.
BIT_ADD
BIT_ADD(expr, expr)
Operand type: BYTE
Result type: Same as operands
Returns the logical ADD of two byte operands; any overflow is disregarded.
“Logical add” is adding the binary content of the two operands as if they were unsigned binary integers. If the sum does not fit in the result field, the overflow is disregarded and the rest is retained.
For example: C8 + 5A = 0122.
SELECT HEX(BIT_ADD(BYTE(x'C8'), BYTE(x'5A')))
Result is hex 22 because the 01 is dropped as part of the carry over.
BIT_AND
BIT_AND(expr, expr)
Operand type: BYTE, IPV4 or IPV6 addresses
Result type: Same as operands
Returns the logical AND of the two operands.
If two bits are 1, the answer is 1; otherwise the answer is 0.
SELECT BIT_AND(IPV4('255.255.255.0'),IPV4('172.16.254.1'))
returns (as an IPv4)
172.16.254.0
BIT_NOT
BIT_NOT(expr)
Operand type: Single BYTE, IPV4 or IPV6 addresses
Result type: Same as operand
Returns the logical NOT of the operand.
SELECT BIT_NOT(IPV4('172.16.254.1'))
returns (as an IPv4):
83.239.1.254
BIT_OR
BIT_OR(expr, expr)
Operand type: BYTE, IPV4 or IPV6 addresses
Result type: Same as operands
Returns the logical OR of one or more operands.
If either or both bits are 1, the answer is 1.
SELECT BIT_OR(IPV4('255.255.255.0'),ipv4('172.16.254.1'))\g
returns (as an IPv4):
255.255.255.1
BIT_XOR
BIT_XOR(expr, expr)
Operand type: BYTE, IPV4 or IPV6 addresses
Result type: Same as operands
Returns the logical XOR of one or more operands.
If either, but not both, bits is 1, the answer is 1; otherwise the answer is 0.
SELECT BIT_XOR(IPV4('255.255.255.0'),IPV4('172.16.254.1'))
returns (as an IPv4)
83.239.1.1
BYTE_AND, BYTE_OR, BYTE_XOR
BYTE_AND(expr, expr)
BYTE_OR(expr, expr)
BYTE_XOR(expr, expr)
Operand type: BYTE, IPV4 or IPV6 addresses
Result type: Same as operands
Returns the logical AND/OR/XOR of the two operands.
If the operands are not of equal length, the shorter one is padded on the right with zero-bytes to make it the same length as the longer one. The result is the length of the longer type.
See the
BIT_AND_AGG(), BIT_OR_AGG(), BIT_XOR_AGG() section for information on bitwise aggregate functions.
Last modified date: 12/19/2024