longFrom

abstract fun longFrom(source: ByteArray, offset: Int): Long(source)

Convert 8 bytes from source ByteArray, starting at index offset, to a Long.

e.g.

val source = 9223372034707292160L
val dest = ByteArray(8) { -100 }
println(dest.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100]

Endian.Big.pack(source, dest, 0)
println(dest.toList())
// [127, -1, -1, -1, -128, 0, 0, 0]
println(Endian.Big.longFrom(dest, 0))
// 9223372034707292160
dest.fill(-100)

Endian.Little.pack(source, dest, 0)
println(dest.toList())
// [0, 0, 0, -128, -1, -1, -1, 127]
println(Endian.Little.longFrom(dest, 0))
// 9223372034707292160

Parameters

source

The ByteArray to access bytes from.

offset

The index to start at when retrieving bytes from source.

See also

Throws

IndexOutOfBoundsException

when not enough bytes are available in array from offset.