Skip to content

Instantly share code, notes, and snippets.

@iximeow
Last active August 29, 2015 14:09
Show Gist options
  • Save iximeow/ce7d7eee5f53e3bda7c1 to your computer and use it in GitHub Desktop.
Save iximeow/ce7d7eee5f53e3bda7c1 to your computer and use it in GitHub Desktop.
SCALAAAAAA
implicit val byteOps: BitOps[Byte] = new BitOps[Byte] {
def >>>(t: Byte, x: Int): Byte = (t >>> x).toByte
def |(a: Byte, b: Byte): Byte = (a | b).toByte
def &(a: Byte, b: Byte): Byte = (a & b).toByte
//Need to put this in an `ArithmeticOps` or something, but this is ok for now
def +(a: Byte, b: Byte): Byte = (a + b).toByte
}
implicit class WithBitOpts[T : BitOps](x: T) {
def >>>(b: Int): T = implicitly[BitOps[T]].>>>(x, b)
def |(b: T): T = implicitly[BitOps[T]].|(x, b)
def &(b: T): T = implicitly[BitOps[T]].&(x, b)
def +(b: T): T = implicitly[BitOps[T]].+(x, b)
}
def charPair2Byte(hi: Char, lo: Char): Byte = {
(hi :: lo :: Nil).map(octet2nibble).reduce((a, b) => a + b)
}
// and SBT output...
[error] found : Int
[error] required: Byte
[error] (hi :: lo :: Nil).map(octet2nibble).reduce((a, b) => a + b)
[error] ^
@matthandlersux
Copy link

give this a ".scala" filename next time for syntax highlighting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment