Using Bitwise Operators

The Not, And, Or, and Xor operators have a second use: they can manipulate the individual bits of integer values. An integer value, in this case, means a value of type Byte, Short, Integer, or Long.

When you apply the Not operator to an integer value, it changes all the 0 bits to 1 and all the 1 bits to 0. Consider, for example, the following variable:

Dim srtStack As Short = 1

In binary, this variable would contain the bits 0000 0000 0000 0001. Executing the following statement would transform this value to 1111 1111 1111 1110 which, on an Intel processor, is equal to –2:

srtStack = Not srtStack

And, Or, and Xor perform bitwise arithmetic when you code them with integral operands. This applies the operator to the first bit ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.