toByteArray

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

Converts a Long 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, 24-bit, 32-bit, 40-bit, 48-bit or 54-bit integers stored in a 'Long' to a byte array.

Parameters

length

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

order

The byte order, default is ByteOrder.BIG_ENDIAN.

Throws

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


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

Converts a ULong 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-ULong.SIZE_BYTES with default value equal to ULong.SIZE_BYTES bytes.

order

The byte order, default is ByteOrder.BIG_ENDIAN.

Throws

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


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.