BitUtil

object BitUtil

A variety of high efficiency bit twiddling routines and encoders for primitives.

Types

Link copied to clipboard
object VH_BE_INT

A VarHandle to read/write big endian int from a byte array. Shape: int vh.get(byte[] arr, int ofs) and void vh.set(byte[] arr, int ofs, int val)

Link copied to clipboard

A VarHandle to read/write big endian short from a byte array. Shape: short vh.get(byte[] arr, int ofs) and void vh.set(byte[] arr, int ofs, short val)

Link copied to clipboard
object VH_LE_INT

A VarHandle to read/write little endian int from a byte array. Shape: int vh.get(byte[] arr, int ofs) and void vh.set(byte[] arr, int ofs, int val)

Link copied to clipboard
object VH_LE_LONG

A VarHandle to read/write little endian long from a byte array. Shape: long vh.get(byte[] arr, int ofs) and void vh.set(byte[] arr, int ofs, long val)

Link copied to clipboard

A VarHandle to read/write little endian short from/to a byte array. Shape: short vh.get(byte[] arr, int ofs) and void vh.set(byte[] arr, int ofs, short val)

Link copied to clipboard

A VarHandle to read/write native endian int from a byte array. Shape: int vh.get(byte[] arr, int ofs) and void vh.set(byte[] arr, int ofs, int val)

Properties

Link copied to clipboard

Native byte order.

Functions

Link copied to clipboard

Extract just the even-bits value as a long from the bit-interleaved value

Link copied to clipboard
fun flipFlop(b: Long): Long

flip flops odd with even bits

Link copied to clipboard
fun interleave(even: Int, odd: Int): Long

Interleaves the first 32 bits of each long value

Link copied to clipboard

Return true if, and only if, the provided integer - treated as an unsigned integer - is either 0 or a power of two.

Link copied to clipboard

returns the next highest power of two, or the current value if it's already a power of two or zero

Link copied to clipboard

Decode an int previously encoded with .zigZagEncode.

Decode a long previously encoded with .zigZagEncode.

Link copied to clipboard

Same as .zigZagEncode but on integers.

Zig-zag encode the provided long. Assuming the input is a signed long whose absolute value can be stored on n bits, the returned value will be an unsigned long that can be stored on n+1 bits.