Q: How to read in scala a long number that was packed in python My scala program receives (through tcp) a long number that was packed in python:
Python sends Long values in that way:
connection.send(struct.pack("!L", 2052))

Scala receives by reading stream:
...
val dataInputStream = new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1"))

val buf = new Array[Char](4)
dataInputStream.read(buf,0,4)
val realLongNum = bufArrayToLongNumber(buf)

My buf array contains number from which I can calculate the required Long number by myself:
def bufArrayToLongNumber(buf:Array[Char]):Long =  
  (buf(0)*256*256*256 + buf(1)*256*256 + buf(2)*256 + buf(3))

I hoped to find an existing function that do this calculation
Is there any?

A: BigInt actually has a constructor which takes Array[Byte] (so you'd have to do convertion from Array[Char]):
val bi = BigInt(buf.map(_.toByte))

That would also handle the situation when your number doesn't fit Long. You could also get Long by just calling bi.longValue.
If you're certain your number will always fit to Long, I'm not sure that it's a better solution than yours.

A: This might work.
val realLongNum = buf.foldLeft(0L){case (a,b) => (a<<4) + b.toLong}

