Appendix C. Operators
The Visual Basic operators fall into five main categories: arithmetic, concatenation, comparison, logical, and bitwise. The following sections explain these categories and the operators they contain. The end of this appendix describes special Date and TimeSpan operators, as well as operator overloading.
ARITHMETIC OPERATORS
The following table lists the arithmetic operators provided by Visual Basic.
OPERATOR | PURPOSE | EXAMPLE | RESULT |
---|---|---|---|
| Exponentiation |
| (2 to the power 3) = |
| Negation |
|
|
| Multiplication |
|
|
| Division |
|
|
| Integer division |
|
|
| Modulus |
|
|
| Addition |
|
|
| Subtraction |
|
|
| Bit left shift |
|
|
| Bit right shift |
|
|
The bit shift operators deserve a little extra discussion. These operators shift the binary representation of a number by a given number of bits either left or right. Unfortunately, Visual Basic doesn't understand binary so you must manually translate between binary and decimal, octal, or hexadecimal.
For example, the hexadecimal value &H57 is 01010111 in binary. If you shift this one bit to the left, you get 10101110, which is &HAE in hexadecimal. If you shift the original value one bit to the right, you get 00101011, which is &H2B in hexadecimal.
When working with binary values, many developers prefer to work in hexadecimal because each hexadecimal digit corresponds to four binary bits so you can work with each group of four bits separately.
CONCATENATION OPERATORS
Visual Basic provides two concatenation ...
Get Visual Basic® 2010 Programmer's Reference 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.