Arithmetic operators in X++ Programming Language

Rumman Ansari   Software Engineer   2023-08-23   649 Share
☰ Table of Contents

Table of Content:


Arithmetic operators in X++ Programming Language

Arithmetic operators are used to make numeric calculations.

Operator Description Example
<< The left shift operator multiplies the left value by 2 by the number of times equal to the value on the right. int a = 1 << 2 (this equals 1*2*2.)
>> The right shift operator divides the left value by 2 by the number of times equal to the value on the right. int a = 1 >> 2 (this equals 1/2/2.)
* This operator multiplies operands. int a = 1*2
/ This operator divides the left value by the right value. int a = 1/2
div The integer division operator performs an integer division of the left value and the right value. int a = 20 div 6 (This returns a division of 3 with a remainder of 2. A = 3)
mod The integer remainder operator returns the remainder of an integer of the left value and the right value. int a = 20 mod 6 (This returns a division of 3 with a remainder of 2. A = 2)
~ The not operator performs a binary not operation. int a = ~1 (This returns -2.)
& The binary AND operator performs a binary operation on the left and right value. This returns the bits in common. int a = 1 & 3 (This returns 1.)
^ The binary XOR operator performs a binary XOR operation on the left and right value. This returns the bits set in one, but not the other. int a = 1 ^ 3 (This returns 2.)
| The binary OR operator performs a binary operation on the left and right value. This returns the bits set in either. int a = 1 | 3 (This returns 3.)
+ The plus operator adds operands. int a = 1 + 4 (This returns 5.)
- The minus operator subtracts the left or right values. int a = 4 - 1 (This returns 3.)
? The ternary operator takes three values. If value 1 is true, value 2 is returned. Else, value 3 is returned. int a = (x > 3) ? 1:5 (If x is greater than 3, then return 1, else return 5.)