Add Short.toByteArray()

This commit is contained in:
Him188 2020-02-19 20:13:57 +08:00
parent abe5db2023
commit c32843fbf3

View File

@ -21,6 +21,16 @@ import kotlin.random.nextInt
* 这些函数为内部函数, 可能会改变
*/
/**
* 255 -> 00 FF
*/
fun Short.toByteArray(): ByteArray = with(toInt()) {
byteArrayOf(
(shr(8) and 0xFF).toByte(),
(shr(0) and 0xFF).toByte()
)
}
/**
* 255 -> 00 00 00 FF
*/