Byte Structures
When we are working with data in form of bytes, we often need to interpret this data in a specific way. Two bytes can represent a short, four bytes can represent an integer, and so on.
Source Types
Primitives extends the functionality of the following types to allow for easy interpretation of data:
ByteArrayArray<Byte>List<Byte>>>MutableList<Byte>
All operations are available for all three types.
Target Types
All data interpretations support the following target types:
| Target Type | Alias | Size | Sample |
|---|---|---|---|
Byte | - | 1 | |
(short, big endian) | - | 2 | |
(short, little endian) | - | 2 | |
(short, big endian) | - | 2 | |
(integer, big endian) | - | 4 | |
(integer, little endian) | - | 4 | |
(integer, big endian) | - | 4 | |
(long, big endian) | - | 8 | |
(long, little endian) | - | 8 | |
(long, big endian) | - | 8 | |
(float, big endian) | - | 4 | |
(float, little endian) | - | 4 | |
(float, big endian) | - | 4 | |
(double, big endian) | - | 8 | |
(double, little endian) | - | 8 | |
(double, big endian) | - | 8 | |
| UnsignedByte | 1 | |
(unsigned short, big endian) | UnsignedShortBE | 2 | |
(unsigned short, little endian) | UnsignedShortLE | 2 | |
(unsigned short, big endian) | UnsignedShort | 2 | |
(unsigned integer, big endian) | UnsignedIntBE | 4 | |
(unsigned integer, little endian) | UnsignedIntLE | 4 | |
(unsigned integer, big endian) | UnsignedInt | 4 | |
(unsigned long, big endian) | UnsignedLongBE | 8 | |
(unsigned long, little endian) | UnsignedLongLE | 8 | |
(unsigned long, big endian) | UnsignedLong | 8 | |
Operations
to
The to function converts the data to a type. This function needs the Array/ByteArray/List to be of the correct size.
import com.shakelang.util.primitives.bytes.toShort
val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toShort()
See all functions
-
toByte()- Converts the data to aByte:[0x01]>>0x01val bytes = byteArrayOf(0x01)
val byte = bytes.toByte() // >> 0x01 -
toShortBE()- Converts the data to aShort(big endian):[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toShortBE() // >> 0x0102 -
toShortLE()- Converts the data to aShort(little endian):[0x01, 0x02]>>0x0201val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toShortLE() // >> 0x0201 -
toShort()- Converts the data to aShort(big endian):[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toShort() // >> 0x0102 -
toIntBE()- Converts the data to aInt(big endian):[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val int = bytes.toIntBE() // >> 0x01020304 -
toIntLE()- Converts the data to aInt(little endian):[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val int = bytes.toIntLE() // >> 0x04030201 -
toInt()- Converts the data to aInt(big endian):[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val int = bytes.toInt() // >> 0x01020304 -
toLongBE()- Converts the data to aLong(big endian):[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val long = bytes.toLongBE() // >> 0x0102030405060708 -
toLongLE()- Converts the data to aLong(little endian):[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val long = bytes.toLongLE() // >> 0x0807060504030201 -
toLong()- Converts the data to aLong(big endian):[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val long = bytes.toLong() // >> 0x0102030405060708 -
toFloatBE()- Converts the data to aFloat(big endian):[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0x80, 0x00, 0x00)
val float = bytes.toFloatBE() // >> 1.0 -
toFloatLE()- Converts the data to aFloat(little endian):[0x00, 0x00, 0x80, 0x3F]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x80, 0x3F)
val float = bytes.toFloatLE() // >> 1.0 -
toFloat()- Converts the data to aFloat(big endian):[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0x80, 0x00, 0x00)
val float = bytes.toFloat() // >> 1.0 -
toDoubleBE()- Converts the data to aDouble(big endian):[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
val double = bytes.toDoubleBE() // >> 1.0 -
toDoubleLE()- Converts the data to aDouble(little endian):[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F)
val double = bytes.toDoubleLE() // >> 1.0 -
toDouble()- Converts the data to aDouble(big endian):[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
val double = bytes.toDouble() // >> 1.0 -
toUByte()- Converts the data to aUByte:[0x01]>>0x01val bytes = byteArrayOf(0x01)
val byte = bytes.toUByte() // >> 0x01 -
toUShortBE()- Converts the data to aUShort(big endian):[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toUShortBE() // >> 0x0102 -
toUShortLE()- Converts the data to aUShort(little endian):[0x01, 0x02]>>0x0201val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toUShortLE() // >> 0x0201 -
toUShort()- Converts the data to aUShort(big endian):[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.toUShort() // >> 0x0102 -
toUIntBE()- Converts the data to aUInt(big endian):[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.toUIntBE() // >> 0x01020304 -
toUIntLE()- Converts the data to aUInt(little endian):[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.toUIntLE() // >> 0x04030201 -
toUInt()- Converts the data to aUInt(big endian):[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.toUInt() // >> 0x01020304 -
toULongBE()- Converts the data to aULong(big endian):[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val short = bytes.toULongBE() // >> 0x0102030405060708 -
toULongLE()- Converts the data to aULong(little endian):[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val short = bytes.toULongLE() // >> 0x0807060504030201 -
toULong()- Converts the data to aULong(big endian):[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val short = bytes.toULong() // >> 0x0102030405060708
get
The get function gets a value from the data at a specific index.
import com.shakelang.util.primitives.bytes.getShort
val bytes = byteArrayOf(0x01, 0x02)
val short = bytes.getShort(0)
import com.shakelang.util.primitives.bytes.getShort
val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short1 = bytes.getShort(1) // >> 0x0203
val short2 = bytes.getShort(0) // >> 0x0102
See all functions
-
getByte(index: Int)- Gets aByteat the index:[0x01]>>0x01val bytes = byteArrayOf(0x01, 0x02)
val byte = bytes.getByte(0) // >> 0x01
val byte = bytes.getByte(1) // >> 0x02 -
getShortBE(index: Int)- Gets aShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.getShortBE(0) // >> 0x0102
val short = bytes.getShortBE(1) // >> 0x0203 -
getShortLE(index: Int)- Gets aShort(little endian) at the index:[0x01, 0x02]>>0x0201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.getShortLE(0) // >> 0x0201
val short = bytes.getShortLE(1) // >> 0x0302 -
getShort(index: Int)- Gets aShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.getShort(0) // >> 0x0102
val short = bytes.getShort(1) // >> 0x0203 -
getIntBE(index: Int)- Gets aInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val int = bytes.getIntBE(0) // >> 0x01020304
val int = bytes.getIntBE(1) // >> 0x02030405 -
getIntLE(index: Int)- Gets aInt(little endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val int = bytes.getIntLE(0) // >> 0x04030201
val int = bytes.getIntLE(1) // >> 0x05040302 -
getInt(index: Int)- Gets aInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val int = bytes.getInt(0) // >> 0x01020304
val int = bytes.getInt(1) // >> 0x02030405 -
getLongBE(index: Int)- Gets aLong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
val long = bytes.getLongBE(0) // >> 0x0102030405060708
val long = bytes.getLongBE(1) // >> 0x0203040506070809 -
getLongLE(index: Int)- Gets aLong(little endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
val long = bytes.getLongLE(0) // >> 0x0807060504030201
val long = bytes.getLongLE(1) // >> 0x0908070605040302 -
getLong(index: Int)- Gets aLong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
val long = bytes.getLong(0) // >> 0x0102030405060708
val long = bytes.getLong(1) // >> 0x0203040506070809 -
getFloatBE(index: Int)- Gets aFloat(big endian) at the index:[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
val float = bytes.getFloatBE(0) // >> 1.0
val float = bytes.getFloatBE(1) // >> 0.0 -
getFloatLE(index: Int)- Gets aFloat(little endian) at the index:[0x00, 0x00, 0x80, 0x3F]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00)
val float = bytes.getFloatLE(0) // >> 1.0
val float = bytes.getFloatLE(1) // >> 0.0 -
getFloat(index: Int)- Gets aFloat(big endian) at the index:[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
val float = bytes.getFloat(0) // >> 1.0
val float = bytes.getFloat(1) // >> 0.0 -
getDoubleBE(index: Int)- Gets aDouble(big endian) at the index:[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
val double = bytes.getDoubleBE(0) // >> 1.0
val double = bytes.getDoubleBE(1) // >> 0.0 -
getDoubleLE(index: Int)- Gets aDouble(little endian) at the index:[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F)
val double = bytes.getDoubleLE(8) // >> 1.0
val double = bytes.getDoubleLE(1) // >> 0.0 -
getDouble(index: Int)- Gets aDouble(big endian) at the index:[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
val double = bytes.getDouble(0) // >> 1.0
val double = bytes.getDouble(1) // >> 0.0 -
getUByte(index: Int)- Gets aUByteat the index:[0x01]>>0x01val bytes = byteArrayOf(0x01, 0x02)
val byte = bytes.getUByte(0) // >> 0x01
val byte = bytes.getUByte(1) // >> 0x02 -
getUShortBE(index: Int)- Gets aUShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.getUShortBE(0) // >> 0x0102
val short = bytes.getUShortBE(1) // >> 0x0203 -
getUShortLE(index: Int)- Gets aUShort(little endian) at the index:[0x01, 0x02]>>0x0201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.getUShortLE(0) // >> 0x0201
val short = bytes.getUShortLE(1) // >> 0x0302 -
getUShort(index: Int)- Gets aUShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
val short = bytes.getUShort(0) // >> 0x0102
val short = bytes.getUShort(1) // >> 0x0203 -
getUIntBE(index: Int)- Gets aUInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val int = bytes.getUIntBE(0) // >> 0x01020304
val int = bytes.getUIntBE(1) // >> 0x02030405 -
getUIntLE(index: Int)- Gets aUInt(little endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val int = bytes.getUIntLE(0) // >> 0x04030201
val int = bytes.getUIntLE(1) // >> 0x05040302 -
getUInt(index: Int)- Gets aUInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
val int = bytes.getUInt(0) // >> 0x01020304
val int = bytes.getUInt(1) // >> 0x02030405 -
getULongBE(index: Int)- Gets aULong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
val long = bytes.getULongBE(0) // >> 0x0102030405060708
val long = bytes.getULongBE(1) // >> 0x0203040506070809 -
getULongLE(index: Int)- Gets aULong(little endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
val long = bytes.getULongLE(0) // >> 0x0807060504030201
val long = bytes.getULongLE(1) // >> 0x0908070605040302 -
getULong(index: Int)- Gets aULong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
val long = bytes.getULong(0) // >> 0x0102030405060708
val long = bytes.getULong(1) // >> 0x0203040506070809
set
The set function sets a value at a specific index.
This function is not available on List<Byte> as it is immutable, but it is available on MutableList<Byte>.
import com.shakelang.util.primitives.bytes.setShort
val bytes = byteArrayOf(0x01, 0x02)
bytes.setShort(0, 0x0304)
import com.shakelang.util.primitives.bytes.setShort
val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setShort(1, 0x0506) // >> [0x01, 0x05, 0x06, 0x04]
See all functions
-
setByte(index: Int, value: Byte)- Sets aByteat the index:[0x01]>>0x01val bytes = byteArrayOf(0x01, 0x02)
bytes.setByte(0, 0x03) // >> [0x03, 0x02] -
setShortBE(index: Int, value: Short)- Sets aShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setShortBE(0, 0x0506) // >> [0x05, 0x06, 0x03, 0x04] -
setShortLE(index: Int, value: Short)- Sets aShort(little endian) at the index:[0x01, 0x02]>>0x0201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setShortLE(0, 0x0506) // >> [0x06, 0x05, 0x03, 0x04] -
setShort(index: Int, value: Short)- Sets aShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setShort(0, 0x0506) // >> [0x05, 0x06, 0x03, 0x04] -
setIntBE(index: Int, value: Int)- Sets aInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.setIntBE(0, 0x090A0B0C) // >> [0x09, 0x0A, 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08] -
setIntLE(index: Int, value: Int)- Sets aInt(little endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.setIntLE(0, 0x090A0B0C) // >> [0x0C, 0x0B, 0x0A, 0x09, 0x05, 0x06, 0x07, 0x08] -
setInt(index: Int, value: Int)- Sets aInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.setInt(0, 0x090A0B0C) // >> [0x09, 0x0A, 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08] -
setLongBE(index: Int, value: Long)- Sets aLong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.setLongBE(0, 0x1112131415161718) // >> [0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
setLongLE(index: Int, value: Long)- Sets aLong(little endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.setLongLE(0, 0x1112131415161718) // >> [0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
setLong(index: Int, value: Long)- Sets aLong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.setLong(0, 0x1112131415161718) // >> [0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
setFloatBE(index: Int, value: Float)- Sets aFloat(big endian) at the index:[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.setFloatBE(0, 1.0f) // >> [0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
setFloatLE(index: Int, value: Float)- Sets aFloat(little endian) at the index:[0x00, 0x00, 0x80, 0x3F]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00)
bytes.setFloatLE(0, 1.0f) // >> [0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
setFloat(index: Int, value: Float)- Sets aFloat(big endian) at the index:[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.setFloat(0, 1.0f) // >> [0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
setDoubleBE(index: Int, value: Double)- Sets aDouble(big endian) at the index:[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.setDoubleBE(0, 1.0) // >> [0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
setDoubleLE(index: Int, value: Double)- Sets aDouble(little endian) at the index:[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.setDoubleLE(0, 1.0) // >> [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
setDouble(index: Int, value: Double)- Sets aDouble(big endian) at the index:[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.setDouble(0, 1.0) // >> [0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
setUByte(index: Int, value: UByte)- Sets aUByteat the index:[0x01]>>0x01val bytes = byteArrayOf(0x01, 0x02)
bytes.setUByte(0, 0x03) // >> [0x03, 0x02] -
setUShortBE(index: Int, value: UShort)- Sets aUShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setUShortBE(0, 0x0506) // >> [0x05, 0x06, 0x03, 0x04] -
setUShortLE(index: Int, value: UShort)- Sets aUShort(little endian) at the index:[0x01, 0x02]>>0x0201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setUShortLE(0, 0x0506) // >> [0x06, 0x05, 0x03, 0x04] -
setUShort(index: Int, value: UShort)- Sets aUShort(big endian) at the index:[0x01, 0x02]>>0x0102val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04)
bytes.setUShort(0, 0x0506) // >> [0x05, 0x06, 0x03, 0x04] -
setUIntBE(index: Int, value: UInt)- Sets aUInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.setUIntBE(0, 0x090A0B0C) // >> [0x09, 0x0A, 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08] -
setUIntLE(index: Int, value: UInt)- Sets aUInt(little endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.setUIntLE(0, 0x090A0B0C) // >> [0x0C, 0x0B, 0x0A, 0x09, 0x05, 0x06, 0x07, 0x08] -
setUInt(index: Int, value: UInt)- Sets aUInt(big endian) at the index:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.setUInt(0, 0x090A0B0C) // >> [0x09, 0x0A, 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08] -
setULongBE(index: Int, value: ULong)- Sets aULong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.setULongBE(0, 0x1112131415161718) // >> [0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
setULongLE(index: Int, value: ULong)- Sets aULong(little endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.setULongLE(0, 0x1112131415161718) // >> [0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
setULong(index: Int, value: ULong)- Sets aULong(big endian) at the index:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.setULong(0, 0x1112131415161718) // >> [0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10]
append
This only works on MutableList<Byte> (array size is fixed, List<Byte> is immutable).
The append function appends a value to the end of the list.
import com.shakelang.util.primitives.bytes.appendShort
val bytes = mutableListOf<Byte>(0x01, 0x02)
bytes.appendShort(0x0304) // >> [0x01, 0x02, 0x03, 0x04]
See all functions
-
appendByte(value: Byte)- Appends aByteto the list:[0x01]>>0x01val bytes = mutableListOf<Byte>(0x01, 0x02)
bytes.appendByte(0x03) // >> [0x01, 0x02, 0x03] -
appendShortBE(value: Short)- Appends aShort(big endian) to the list:[0x01, 0x02]>>0x0102val bytes = mutableListOf<Byte>(0x01, 0x02)
bytes.appendShortBE(0x0304) // >> [0x01, 0x02, 0x03, 0x04] -
appendShortLE(value: Short)- Appends aShort(little endian) to the list:[0x01, 0x02]>>0x0201val bytes = mutableListOf<Byte>(0x01, 0x02)
bytes.appendShortLE(0x0304) // >> [0x01, 0x02, 0x04, 0x03] -
appendShort(value: Short)- Appends aShort(big endian) to the list:[0x01, 0x02]>>0x0102val bytes = mutableListOf<Byte>(0x01, 0x02)
bytes.appendShort(0x0304) // >> [0x01, 0x02, 0x03, 0x04] -
appendIntBE(value: Int)- Appends aInt(big endian) to the list:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04)
bytes.appendIntBE(0x05060708) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08] -
appendIntLE(value: Int)- Appends aInt(little endian) to the list:[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04)
bytes.appendIntLE(0x05060708) // >> [0x01, 0x02, 0x03, 0x04, 0x08, 0x07, 0x06, 0x05] -
appendInt(value: Int)- Appends aInt(big endian) to the list:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04)
bytes.appendInt(0x05060708) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08] -
appendLongBE(value: Long)- Appends aLong(big endian) to the list:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.appendLongBE(0x090A0B0C0D0E0F10) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
appendLongLE(value: Long)- Appends aLong(little endian) to the list:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.appendLongLE(0x090A0B0C0D0E0F10) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09] -
appendLong(value: Long)- Appends aLong(big endian) to the list:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.appendLong(0x090A0B0C0D0E0F10) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10] -
appendFloatBE(value: Float)- Appends aFloat(big endian) to the list:[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = mutableListOf<Byte>(0x3F, 0x80, 0x00, 0x00)
bytes.appendFloatBE(1.0f) // >> [0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00] -
appendFloatLE(value: Float)- Appends aFloat(little endian) to the list:[0x00, 0x00, 0x80, 0x3F]>>1.0val bytes = mutableListOf<Byte>(0x00, 0x00, 0x80, 0x3F)
bytes.appendFloatLE(1.0f) // >> [0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F] -
appendFloat(value: Float)- Appends aFloat(big endian) to the list:[0x3F, 0x80, 0x00, 0x00]>>1.0val bytes = mutableListOf<Byte>(0x3F, 0x80, 0x00, 0x00)
bytes.appendFloat(1.0f) // >> [0x3F, 0x80, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00] -
appendDoubleBE(value: Double)- Appends aDouble(big endian) to the list:[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = mutableListOf<Byte>(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.appendDoubleBE(1.0) // >> [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
appendDoubleLE(value: Double)- Appends aDouble(little endian) to the list:[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F]>>1.0val bytes = mutableListOf<Byte>(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.appendDoubleLE(1.0) // >> [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F] -
appendDouble(value: Double)- Appends aDouble(big endian) to the list:[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]>>1.0val bytes = mutableListOf<Byte>(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
bytes.appendDouble(1.0) // >> [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] -
appendUByte(value: UByte)- Appends aUByteto the list:[0x01]>>0x01val bytes = mutableListOf<Byte>(0x01, 0x02)
bytes.appendUByte(0x03) // >> [0x01, 0x02, 0x03] -
appendUShortBE(value: UShort)- Appends aUShort(big endian) to the list:[0x01, 0x02]>>0x0102val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04)
bytes.appendUShortBE(0x0506) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06] -
appendUShortLE(value: UShort)- Appends aUShort(little endian) to the list:[0x01, 0x02]>>0x0201val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04)
bytes.appendUShortLE(0x0506) // >> [0x01, 0x02, 0x03, 0x04, 0x06, 0x05] -
appendUShort(value: UShort)- Appends aUShort(big endian) to the list:[0x01, 0x02]>>0x0102val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04)
bytes.appendUShort(0x0506) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06] -
appendUIntBE(value: UInt)- Appends aUInt(big endian) to the list:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.appendUIntBE(0x090A0B0C) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C] -
appendUIntLE(value: UInt)- Appends aUInt(little endian) to the list:[0x01, 0x02, 0x03, 0x04]>>0x04030201val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.appendUIntLE(0x090A0B0C) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0B, 0x0A, 0x09] -
appendUInt(value: UInt)- Appends aUInt(big endian) to the list:[0x01, 0x02, 0x03, 0x04]>>0x01020304val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
bytes.appendUInt(0x090A0B0C) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C] -
appendULongBE(value: ULong)- Appends aULong(big endian) to the list:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.appendULongBE(0x1112131415161718) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18] -
appendULongLE(value: ULong)- Appends aULong(little endian) to the list:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0807060504030201val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.appendULongLE(0x1112131415161718) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11] -
appendULong(value: ULong)- Appends aULong(big endian) to the list:[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]>>0x0102030405060708val bytes = mutableListOf<Byte>(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10)
bytes.appendULong(0x1112131415161718) // >> [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18]
Conversion to bytes
from
To convert the data back to byte arrays, you can just apply toBytes() to the data.
import com.shakelang.util.primitives.bytes.toBytes
val bytes = 0x0102.toBytes() // >> [0x01, 0x02]
For Short, Int, Long, Float, Double, USort, UInt, ULong you can also use the toBytesBE() and toBytesLE() functions.
import com.shakelang.util.primitives.bytes.toBytesBE
val bytes = 0x0102.toBytesBE() // >> [0x01, 0x02]
import com.shakelang.util.primitives.bytes.toBytesLE
val bytes = 0x0102.toBytesLE() // >> [0x02, 0x01]
(For Byte and UByte this is not necessary as there is only one byte, so there is no point in having
a big endian and little endian version)
See all functions
Byte.toBytes()- Converts aByteto a byte array:0x01>>[0x01]Short.toBytesBE()- Converts aShort(big endian) to a byte array:0x0102>>[0x01, 0x02]Short.toBytesLE()- Converts aShort(little endian) to a byte array:0x0102>>[0x02, 0x01]Short.toBytes()- Converts aShort(big endian) to a byte array:0x0102>>[0x01, 0x02]Int.toBytesBE()- Converts aInt(big endian) to a byte array:0x01020304>>[0x01, 0x02, 0x03, 0x04]Int.toBytesLE()- Converts aInt(little endian) to a byte array:0x01020304>>[0x04, 0x03, 0x02, 0x01]Int.toBytes()- Converts aInt(big endian) to a byte array:0x01020304>>[0x01, 0x02, 0x03, 0x04]Long.toBytesBE()- Converts aLong(big endian) to a byte array:0x0102030405060708>>[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]Long.toBytesLE()- Converts aLong(little endian) to a byte array:0x0102030405060708>>[0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01]Long.toBytes()- Converts aLong(big endian) to a byte array:0x0102030405060708>>[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]Float.toBytesBE()- Converts aFloat(big endian) to a byte array:1.0>>[0x3F, 0x80, 0x00, 0x00]Float.toBytesLE()- Converts aFloat(little endian) to a byte array:1.0>>[0x00, 0x00, 0x80, 0x3F]Float.toBytes()- Converts aFloat(big endian) to a byte array:1.0>>[0x3F, 0x80, 0x00, 0x00]Double.toBytesBE()- Converts aDouble(big endian) to a byte array:1.0>>[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]Double.toBytesLE()- Converts aDouble(little endian) to a byte array:1.0>>[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F]Double.toBytes()- Converts aDouble(big endian) to a byte array:1.0>>[0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]UByte.toBytes()- Converts aUByteto a byte array:0x01>>[0x01]UShort.toBytesBE()- Converts aUShort(big endian) to a byte array:0x0102>>[0x01, 0x02]UShort.toBytesLE()- Converts aUShort(little endian) to a byte array:0x0102>>[0x02, 0x01]UShort.toBytes()- Converts aUShort(big endian) to a byte array:0x0102>>[0x01, 0x02]UInt.toBytesBE()- Converts aUInt(big endian) to a byte array:0x01020304>>[0x01, 0x02, 0x03, 0x04]UInt.toBytesLE()- Converts aUInt(little endian) to a byte array:0x01020304>>[0x04, 0x03, 0x02, 0x01]UInt.toBytes()- Converts aUInt(big endian) to a byte array:0x01020304>>[0x01, 0x02, 0x03, 0x04]ULong.toBytesBE()- Converts aULong(big endian) to a byte array:0x0102030405060708>>[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]ULong.toBytesLE()- Converts aULong(little endian) to a byte array:0x0102030405060708>>[0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01]ULong.toBytes()- Converts aULong(big endian) to a byte array:0x0102030405060708>>[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
of
This set of functions creates data from raw bytes.
byteOf(b0: Byte)- Creates aBytefrom a byte:0x01>>0x01shortOf(b0: Byte, b1: Byte)- Creates aShortfrom two bytes:0x01, 0x02>>0x0102intOf(b0: Byte, b1: Byte, b2: Byte, b3: Byte)- Creates aIntfrom four bytes:0x01, 0x02, 0x03, 0x04>>0x01020304longOf(b0: Byte, b1: Byte, b2: Byte, b3: Byte, b4: Byte, b5: Byte, b6: Byte, b7: Byte)- Creates aLongfrom eight bytes:0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08>>0x0102030405060708floatOf(b0: Byte, b1: Byte, b2: Byte, b3: Byte)- Creates aFloatfrom four bytes:0x3F, 0x80, 0x00, 0x00>>1.0doubleOf(b0: Byte, b1: Byte, b2: Byte, b3: Byte, b4: Byte, b5: Byte, b6: Byte, b7: Byte)- Creates aDoublefrom eight bytes:0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00>>1.0ubyteOf(b0: Byte)- Creates aUBytefrom a byte:0x01>>0x01ushortOf(b0: Byte, b1: Byte)- Creates aUShortfrom two bytes:0x01, 0x02>>0x0102uintOf(b0: Byte, b1: Byte, b2: Byte, b3: Byte)- Creates aUIntfrom four bytes:0x01, 0x02, 0x03, 0x04>>0x01020304ulongOf(b0: Byte, b1: Byte, b2: Byte, b3: Byte, b4: Byte, b5: Byte, b6: Byte, b7: Byte)- Creates aULongfrom eight bytes:0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08>>0x0102030405060708
import com.shakelang.util.primitives.bytes.byteOf
val bytes = byteOf(0x01)
import com.shakelang.util.primitives.bytes.shortOf
val bytes = shortOf(0x01, 0x02)
import com.shakelang.util.primitives.bytes.intOf
val bytes = intOf(0x01, 0x02, 0x03, 0x04)
import com.shakelang.util.primitives.bytes.longOf
val bytes = longOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)
import com.shakelang.util.primitives.bytes.floatOf
val bytes = floatOf(0x3F, 0x80, 0x00, 0x00)
import com.shakelang.util.primitives.bytes.doubleOf
val bytes = doubleOf(0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
import com.shakelang.util.primitives.bytes.ubyteOf
val bytes = ubyteOf(0x01)
import com.shakelang.util.primitives.bytes.ushortOf
val bytes = ushortOf(0x01, 0x02)
import com.shakelang.util.primitives.bytes.uintOf
val bytes = uintOf(0x01, 0x02, 0x03, 0x04)
import com.shakelang.util.primitives.bytes.ulongOf
val bytes = ulongOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08)