vito-Z80

uByte bits

Jul 26th, 2019
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.29 KB | None | 0 0
  1. fun isBitSet(byte: UInt): Boolean {
  2.         return (byte xor 1u).toUByte() < byte
  3.     }
  4.  
  5.     fun UByte.getBits(): Array<Boolean> {
  6.         return Array(8) {
  7.             isBitSet(this.toUInt() shr it)
  8.         }
  9.     }
  10.  
  11.     fun UInt.setBit(bit: Int): UByte = this.or(1u shl bit).toUByte()
Advertisement
Add Comment
Please, Sign In to add comment