Created
October 23, 2012 04:48
-
-
Save fbettag/3936752 to your computer and use it in GitHub Desktop.
UDP NetFlow 2 bytes to get Int/Long
This file contains hidden or 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
def toLong(buf: Array[byte], offset: Int, length: Int) = { | |
var ret = 0L | |
var i = offset | |
while (i < offset + length) { | |
ret = ((ret << 8) & 0xffffffff) + (buf(i) & 0xff) | |
i += 1 | |
} | |
ret | |
} | |
val myL = toLong(byteArray, 0, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably more functional...
...or even tail-recursive:
scnr, Martin's FP course does have some side effects ;-)