toByteArray

fun Int.toByteArray(order: ByteOrder = ByteOrder.BIG_ENDIAN, length: Int = Int.SIZE_BYTES): ByteArray

Converts an Int to a byte array using the given endianness.

The optional length parameter allows you to specify the actual length of the field, to convert 8-bit, 16-bit or 24-bit integers stored in an Int to a byte array.

Parameters

length

The length of the field, in bytes, within the range of 1-Int.SIZE_BYTES with default value equal to Int.SIZE_BYTES bytes.

order

The byte order, default is ByteOrder.BIG_ENDIAN.

Throws

If the length is not within the range of 1 to Int.SIZE_BYTES.


fun UInt.toByteArray(order: ByteOrder = ByteOrder.BIG_ENDIAN, length: Int = UInt.SIZE_BYTES): ByteArray

Converts an UInt to a byte array using the given endianness.

The optional length parameter allows you to specify the actual length of the field, to convert 8-bit, 16-bit or 24-bit integers stored in an UInt to a byte array.

Parameters

length

The length of the field, in bytes, within the range of 1-UInt.SIZE_BYTES with default value equal to UInt.SIZE_BYTES bytes.

order

The byte order, default is ByteOrder.BIG_ENDIAN.

Throws

If the length is not within the range of 1 to UInt.SIZE_BYTES.


fun Short.toByteArray(order: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray

Converts a Short to a byte array using the given endianness.

Parameters

order

The byte order, default is ByteOrder.BIG_ENDIAN.


fun UShort.toByteArray(order: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray

Converts a UShort to a byte array using the given endianness.

Parameters

order

The byte order, default is ByteOrder.BIG_ENDIAN.


Converts a Byte to a byte array.


Converts a UByte to a byte array.


fun HexString.toByteArray(format: HexFormat = HexFormat.UpperCase): ByteArray

Converts a byte array to a hex string.

Parameters

format

The format of the hex string.


fun UUID.toByteArray(order: ByteOrder = ByteOrder.BIG_ENDIAN): ByteArray

Converts a 128-bit UUID to a byte array.

Parameters

order

The byte order, default is ByteOrder.BIG_ENDIAN.