Last active
August 29, 2015 14:09
-
-
Save iximeow/ce7d7eee5f53e3bda7c1 to your computer and use it in GitHub Desktop.
SCALAAAAAA
This file contains 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
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] ^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
give this a ".scala" filename next time for syntax highlighting