Package-level declarations

This package contains extension methods for binary operations and byte array conversions.

Types

Link copied to clipboard

Double precision floating point format enumeration.

Link copied to clipboard

Floating point format enumeration.

Link copied to clipboard
typealias HexString = String

A type alias for a String containing a hex value.

Link copied to clipboard

Integer format enumeration.

Functions

Link copied to clipboard
infix fun Byte.and(other: Int): Byte

Binary AND operation on a Byte type.

infix fun Short.and(other: Int): Short

Binary AND operation on a Short type.

infix fun UByte.and(other: Int): UByte

Binary AND operation on a UByte type.

infix fun UShort.and(other: Int): UShort

Binary AND operation on a UShort type.

Link copied to clipboard
fun ByteArray.getDouble(offset: Int, format: DoubleFormat = DoubleFormat.IEEE_754_DOUBLE_PRECISION, order: ByteOrder = ByteOrder.BIG_ENDIAN): Double

Returns a Double value from a byte array with a given offset.

Link copied to clipboard
fun ByteArray.getFloat(offset: Int, format: FloatFormat, order: ByteOrder = ByteOrder.BIG_ENDIAN): Float

Returns a Float value from a byte array with a given offset.

Link copied to clipboard
fun ByteArray.getInt(offset: Int, order: ByteOrder = ByteOrder.BIG_ENDIAN): Int
fun ByteArray.getInt(offset: Int, format: IntFormat, order: ByteOrder = ByteOrder.BIG_ENDIAN): Int

Returns an Int from a byte array with a given offset.

Link copied to clipboard
fun ByteArray.getShort(offset: Int, order: ByteOrder = ByteOrder.BIG_ENDIAN): Short

Returns an Int from a byte array with a given offset.

Link copied to clipboard
fun ByteArray.getUInt(offset: Int, format: IntFormat = IntFormat.UINT32, order: ByteOrder = ByteOrder.BIG_ENDIAN): UInt

Returns an Int from a byte array with a given offset.

Link copied to clipboard
fun ByteArray.getUShort(offset: Int, order: ByteOrder = ByteOrder.BIG_ENDIAN): UShort

Returns an Int from a byte array with a given offset.

Link copied to clipboard
fun ByteArray.getUuid(offset: Int, order: ByteOrder = ByteOrder.BIG_ENDIAN): UUID

Converts a byte array to a 128-bit UUID.

Link copied to clipboard
infix fun Byte.hasAllBitsCleared(mask: Int): Boolean

Returns whether ALL bits that are equal to 1 in the given mask are set to 0 in the receiver.

Link copied to clipboard
infix fun Byte.hasAllBitsSet(mask: Int): Boolean
infix fun UByte.hasAllBitsSet(mask: Int): Boolean

Returns whether ALL bits that are equal to 1 in the given mask are also set to 1 in the receiver.

Link copied to clipboard
infix fun Byte.hasBitCleared(bit: Int): Boolean
infix fun Int.hasBitCleared(bit: Int): Boolean
infix fun Short.hasBitCleared(bit: Int): Boolean
infix fun UByte.hasBitCleared(bit: Int): Boolean
infix fun UInt.hasBitCleared(bit: Int): Boolean
infix fun UShort.hasBitCleared(bit: Int): Boolean

Returns whether the bit at the given bit is set to 0 in the receiver.

Link copied to clipboard
infix fun Byte.hasBitSet(bit: Int): Boolean
infix fun Int.hasBitSet(bit: Int): Boolean
infix fun Short.hasBitSet(bit: Int): Boolean
infix fun UByte.hasBitSet(bit: Int): Boolean
infix fun UInt.hasBitSet(bit: Int): Boolean
infix fun UShort.hasBitSet(bit: Int): Boolean

Returns whether the bit at the given bit is set to 1 in the receiver.

Link copied to clipboard
infix fun Byte.or(other: Int): Byte

Binary OR operation on a Byte type.

infix fun Short.or(other: Int): Short

Binary OR operation on a Short type.

infix fun UByte.or(other: Int): UByte

Binary OR operation on a UByte type.

infix fun UShort.or(other: Int): UShort

Binary OR operation on a UShort type.

Link copied to clipboard
infix fun Byte.shl(bitCount: Int): Byte
infix fun Short.shl(bitCount: Int): Short
infix fun UByte.shl(bitCount: Int): UByte
infix fun UShort.shl(bitCount: Int): UShort

Shifts this value left by the bitCount number of bits.

Link copied to clipboard
infix fun Byte.shr(bitCount: Int): Byte
infix fun Short.shr(bitCount: Int): Short

Shifts this value right by the bitCount number of bits, filling the leftmost bits with copies of the sign bit.

infix fun UByte.shr(bitCount: Int): UByte
infix fun UShort.shr(bitCount: Int): UShort

Shifts this value right by the bitCount number of bits, filling the leftmost bits with zeros.

Link copied to clipboard

Converts a Byte to a byte array.

Converts a UByte to a byte array.

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

Converts a 128-bit UUID to a byte array.

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

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

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

Converts a byte array to a hex string.

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

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

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.

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.

Link copied to clipboard
fun ByteArray.toHexString(prefixOx: Boolean = false, format: HexFormat = HexFormat.UpperCase): HexString

Converts a byte array to a hex string.

Link copied to clipboard
fun ByteArray.toUuid(order: ByteOrder = ByteOrder.BIG_ENDIAN): UUID

Converts a byte array to a 128-bit UUID.

Link copied to clipboard
infix fun Byte.ushr(bitCount: Int): Byte
infix fun Short.ushr(bitCount: Int): Short

Shifts this value right by the bitCount number of bits, filling the leftmost bits with zeros.

Link copied to clipboard
infix fun Byte.xor(other: Int): Byte

Binary XOR operation on a Byte type.

infix fun ByteArray.xor(other: ByteArray): ByteArray

Applies the XOR operator on two byte arrays. Compared to already existent xor functions, this one does not require the arrays to be of the same length.

infix fun Short.xor(other: Int): Short

Binary XOR operation on a Short type.

infix fun UByte.xor(other: Int): UByte

Binary XOR operation on a UByte type.

infix fun UShort.xor(other: Int): UShort

Binary XOR operation on a UShort type.