I l@ve RuBoard Previous Section Next Section

11.1 Bit Operators

Bit, or bitwise, operators allow the programmer to work on individual bits. For example, a short integer holds 16 bits (on most machines). The bit operators treat each of these as an independent bit. By contrast, an add operator treats the 16 bits as a single 16-bit number.

Bit operators allow you to set, clear, test, and perform other operations on bits. The bit operators are listed in Table 11-2.

Table 11-2. Bit operators

Operator

Meaning

&

Bitwise AND

|

Bitwise OR

^

Bitwise exclusive OR

~

Complement

<<

Shift left

>>

Shift right

These operators work on any integer or character-data type.

    I l@ve RuBoard Previous Section Next Section