Skip to content

Instantly share code, notes, and snippets.

@ft975
Created June 26, 2013 16:35
Show Gist options
  • Save ft975/5869013 to your computer and use it in GitHub Desktop.
Save ft975/5869013 to your computer and use it in GitHub Desktop.
def splitIntoNibbles(x: Short): Array[Byte] = {
val byteArray = new Array[Byte](4)
byteArray(0) = ((x & 0x000F) >> 0).toByte
byteArray(1) = ((x & 0x00F0) >> 2).toByte
byteArray(2) = ((x & 0x0F00) >> 4).toByte
byteArray(3) = ((x & 0xF000) >> 6).toByte
byteArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment