본문 바로가기

Kotlin

Long to ByteArray Extension

import java.nio.ByteBuffer

fun Long.toByteArray(): ByteArray {
    val buffer: ByteBuffer = ByteBuffer.allocate(java.lang.Long.BYTES)
    buffer.putLong(this)
    return buffer.array()
}