add an Int extension for flipping a bit

This commit is contained in:
tibbi 2018-03-08 12:33:26 +01:00
parent d5b08c27d8
commit f4bbcabff5

View file

@ -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<Int>.random() = Random().nextInt(endInclusive - start) + start
// taken from https://stackoverflow.com/a/40964456/1967672