Bitwise operators

You can use the following operators on all unscaled integer data types, in both Sybase IQ and Adaptive Server Enterprise.

Operator

Description

&

AND

|

OR

^

EXCLUSIVE OR

~

NOT


The AND operator (&)

Bit 1

Bit 2

Bit 1 & Bit 2

0

0

0

0

1

0

1

0

0

1

1

1

The AND operator compares 2 bits. If they are both 1, the result is 1.


Bitwise OR (|)

Bit 1

Bit 2

Bit 1 | Bit 2

0

0

0

0

1

1

1

0

1

1

1

1

The OR operator compares 2 bits. If one or the other bit is 1, the result is 1.


EXCLUSIVE OR (^)

The EXCLUSIVE OR operator results in a 1 when either, but not both, of its two operands is 1.

Bit 1

Bit 2

Bit 1 ^Bit 2

0

0

0

0

1

1

1

0

1

1

1

0


NOT (~)

The NOT operator is a unary operator that returns the inverse of its operand.

Bit

~ Bit

1

0

0

1