.::kotlin::. Bit mask with xor
\nclass Solution {\n    fun findComplement(num: Int): Int {\n        var i = 0\n        var t = num\n        while (t > 0) {\n            t = t shr 1\n         
```\nclass Solution {\n    fun findComplement(num: Int): Int {\n        var i = 0\n        var t = num\n        while (t > 0) {\n            t = t shr 1\n            i++\n        }\n        val mask = (1 shl i) - 1 // -1 is the trick to make mask 1000 -> 111\n        return num xor mask\n    }\n}\n```
['Kotlin']