Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / DaxGeek / Arithmetic Operators

Arithmetic Operators

Hossein.K Profile Picture Hossein.K 6,648
Arithmetic operators perform calculations in X++. Arithmetic operators are used
like relational operators except for '~, ++,
--, +=, and -='. The following table
defines available arithmetic operators:
Operator Term Description
+ Plus Adds expression1 to expression2.
- Minus Subtracts expression2 from expression1.
* Multiply Multiplies expression1 with expression2.
/ Divide Divides expression1 with expression2.
DIV Integer
division
Performs an integer division of expression1
with expression2.
MOD Integer
remainder
Returns the rest of an integer division of
expression1 with expression2.
~ Not Unary operator: performs a binary not
operation.
& Binary
And
Performs a binary and-operation on expression1
and expression2.
^ Binary
XOR
Performs a binary XOR-operation on
expression1 and expression2.
| Binary Or Performs a binary or-operation on expression1
and expression2.
<< Left shift Performs expression2 left shift (a multiplication
with two) on expression1.
>> Right shift Performs expression2 right shift (a division by
two) on expression1.
? Ternary
operator
Takes three expressions: expression1 ?
expression2 : expression3. If expression1 is
true, expression2 is returned otherwise
expression3 is returned.

The following are some examples of these arithmetic operators. For all examples,
the variable '
i' is an integer.
Evaluated Expression Return Value
i++; Increments the i variable by one.
i--; Decrements the i variable by one.
i += 2; Increments the i variable by two every time.
i -= 3; Decrements the i variable by three every time.
i = 3 << 3 i = 24 (i = 3*2*2*2)


i = 24 >> 2 i = 6 (i = 24/2/2)
i = 80 DIV 13 i = 6 (6 is the largest number that 13 can be
multiplied by, where the result is less than or
equal to 80. In this case, 6*13 = 78, remainder
2)
i = 80 MOD 13 i = 2 (2 is the remainder after dividing 80 by
13)

NOTE: View more examples of arithmetic operators in the "X++ Online Help
Guide.
 "

Best Regards,
Hossein Karimi

Comments

*This post is locked for comments