-
-
Save adityabhaskar/fe76f4ae7be7e5373d88fb9b1c3c765a to your computer and use it in GitHub Desktop.
Allows simple bit flags operation on int values in kotlin. Inspired by: http://stackoverflow.com/a/40588216/4433326
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("NOTHING_TO_INLINE") | |
import kotlin.experimental.and // Used for Byte | |
import kotlin.experimental.inv // Used for Byte | |
import kotlin.experimental.or // Used for Byte | |
inline fun Int.hasFlag(flag: Int) = flag and this == flag | |
inline fun Int.withFlag(flag: Int) = this or flag | |
inline fun Int.minusFlag(flag: Int) = this and flag.inv() | |
inline fun Byte.hasFlag(flag: Byte) = flag and this == flag | |
inline fun Byte.withFlag(flag: Byte) = this or flag | |
inline fun Byte.minusFlag(flag: Byte) = this and flag.inv() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment