Kotlin Programming Cookbook
上QQ阅读APP看书,第一时间看更新

inv

The inv function simply inverts the bit patterns. If the bit is 1, it makes it 0 and vice versa.

Here's an example:

fun main(args: Array<String>) {
val a=2
print(a.inv())}

This is the output:

 -3

The following is the explanation:

2 = 10 (Binary format)

Bitwise complement of 2 = 01, but the compiler shows 2’s complement of that number, which is the negative notation of the binary number.

2’s complement of an integer n is equal to -(n+1).