最近自己优化内存用到的代码直接贴出来给你了。
```
object BitStatesUtils {
const val isFavorite = (1L shl 0).toByte()
const val isDownload = (1L shl 1).toByte()
const val isTrashed = (1L shl 2).toByte()
public const val SIZE_BITS: Byte = 0
/**
* @
param states 所有状态值
* @
param value 需要判断状态值
* @
return 是否存在
*/
fun hasState(states: Byte, value: Byte): Boolean {
val byte = (states and value) as Byte
return byte != SIZE_BITS
}
fun Byte.HasState(value: Byte): Boolean {
return BitStatesUtils.hasState(this, value)
}
/**
* @
param states 已有状态值
* @
param value 需要添加状态值
* @
return 新的状态值
*/
fun addState(states: Byte, value: Byte): Byte {
return if (hasState(states, value)) {
states
} else (states or value)
}
fun Byte.AddState(value: Byte): Byte {
return addState(this, value)
}
/**
* @
param states 已有状态值
* @
param value 需要删除状态值
* @
return 新的状态值
*/
fun removeState(states: Byte, value: Byte): Byte {
return if (!hasState(states, value)) {
states
} else (states xor value)
}
}
```