contents.gifindex.gif

Arithmetic Operators

Operator

Example

Result

Description

-

-A

Twos complement (negation)

dash (minus sign)

-

A-B

Subtraction

dash

+

A+B

Addition

plus sign

Not Valid for Sets

Operator

Example

Result

Description

*

A*B

Multiplication

asterisk

/

A/B

Unsigned integer division

forward slash

%

A%B

Modulus: remainder from /

percent sign

<<

A<<B

Shift A left by B bits

double left angle bracket

>>

A>>B

Shift A right by B bits

double right angle bracket

Note: A minus sign has a different significance depending on how you use it. When used with one operand, it indicates that the twos complement of the operand is to be formed. When the minus sign is found between two operands, the twos complements of the second operand is added to the first.


Arithmetic operators define arithmetic relationships between items in an expression. The shift operators are included in this class because each left shift of one bit is equivalent to multiplication by 2 and a right shift of one bit is the same as division by 2.

Division is unsigned integer division: the result of division is a positive integer. The remainder of a division can be obtained by using the modulus operator, "%." The shift operators perform logical unsigned shifts. Zeros are shifted in from the left during right shifts and in from the right during left shifts.


See Also

Logical Operators

Relational Operators

Assignment Operators