Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculation order of bitwise operators in Kotlin

Tags:

kotlin

I can't find information about calculation order of bitwise operators in Kotlin. Is it same as in Java or they compute from left to right without any priority?

like image 245
Sergei Vasilenko Avatar asked Nov 16 '17 13:11

Sergei Vasilenko


People also ask

How does bitwise operator work in Kotlin?

Kotlin provides several functions (in infix form) to perform bitwise and bitshift operation. In this article, you will learn to perform bit level operation in Kotlin with the help of examples. Bitwise and bit shift operators are used on only two integral types ( Int and Long ) to perform bit-level operations.

What does || mean in Kotlin?

There are two logical operators in Kotlin: || :true if either of the Boolean expression is true. and. &&: true if all Boolean expressions are true. Note that, or and and are functions that support infix notations .


1 Answers

The and, or xor and other infix functions for bitwise operations are not operators per se, and their execution order is the same as that of other infix functions, i.e. from left to right, so these two lines are equivalent:

a or b and c or d and e

(((a or b) and c) or d) and e

Also note that the precedence of the infix functions is lower than that of operators:

1 + 2 and 3 + 4

(1 + 2) and (3 + 4)
like image 74
hotkey Avatar answered Oct 21 '22 13:10

hotkey