From f4bbcabff5a494af28cad44df3ae8da9bb5f4d3d Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 8 Mar 2018 12:33:26 +0100 Subject: [PATCH] add an Int extension for flipping a bit --- .../main/kotlin/com/simplemobiletools/commons/extensions/Int.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt index 2dd73d0ae..6b56a6779 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Int.kt @@ -39,6 +39,8 @@ fun Int.removeBit(bit: Int) = addBit(bit) - bit fun Int.addBit(bit: Int) = this or bit +fun Int.flipBit(bit: Int) = if (this and bit == 0) addBit(bit) else removeBit(bit) + fun ClosedRange.random() = Random().nextInt(endInclusive - start) + start // taken from https://stackoverflow.com/a/40964456/1967672