add an Int extension for flipping a bit
This commit is contained in:
parent
d5b08c27d8
commit
f4bbcabff5
1 changed files with 2 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue