public class BitUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
CACHE_LINE_LENGTH
Length of the data blocks used by the CPU cache sub-system in bytes.
|
static int |
SIZE_OF_BOOLEAN
Size of a boolean in bytes
|
static int |
SIZE_OF_BYTE
Size of a byte in bytes
|
static int |
SIZE_OF_CHAR
Size of a char in bytes
|
static int |
SIZE_OF_DOUBLE
Size of a double in bytes
|
static int |
SIZE_OF_FLOAT
Size of a a float in bytes
|
static int |
SIZE_OF_INT
Size of an int in bytes
|
static int |
SIZE_OF_LONG
Size of a long in bytes
|
static int |
SIZE_OF_SHORT
Size of a short in bytes
|
Constructor and Description |
---|
BitUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
align(int value,
int alignment)
Align a value to the next multiple up of alignment.
|
static int |
calculateShiftForScale(int scale)
Calculate the shift value to scale a number based on how refs are compressed or not.
|
static int |
findNextPositivePowerOfTwo(int value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.
|
static byte[] |
fromHex(java.lang.String string)
Generate a byte array from a string that is the hex representation of the given byte array.
|
static byte[] |
fromHexByteArray(byte[] buffer)
Generate a byte array from the hex representation of the given byte array.
|
static int |
generateRandomisedId()
Generate a randomized integer over [
Integer.MIN_VALUE , Integer.MAX_VALUE ] suitable for
use as an Aeron Id. |
static boolean |
isAligned(long address,
int alignment)
Is an address aligned on a boundary.
|
static boolean |
isEven(int value)
Is a number even.
|
static boolean |
isPowerOfTwo(int value)
Is a value a positive power of two.
|
static int |
next(int current,
int max)
Cycles indices of an array one at a time in a forward fashion
|
static int |
previous(int current,
int max)
Cycles indices of an array one at a time in a backwards fashion
|
static java.lang.String |
toHex(byte[] buffer)
Generate a string that is the hex representation of a given byte array.
|
static java.lang.String |
toHex(byte[] buffer,
int offset,
int length)
Generate a string that is the hex representation of a given byte array.
|
static byte[] |
toHexByteArray(byte[] buffer)
Generate a byte array that is a hex representation of a given byte array.
|
static byte[] |
toHexByteArray(byte[] buffer,
int offset,
int length)
Generate a byte array that is a hex representation of a given byte array.
|
public static final int SIZE_OF_BYTE
public static final int SIZE_OF_BOOLEAN
public static final int SIZE_OF_CHAR
public static final int SIZE_OF_SHORT
public static final int SIZE_OF_INT
public static final int SIZE_OF_FLOAT
public static final int SIZE_OF_LONG
public static final int SIZE_OF_DOUBLE
public static final int CACHE_LINE_LENGTH
public static int findNextPositivePowerOfTwo(int value)
If the value is <= 0 then 1 will be returned.
This method is not suitable for Integer.MIN_VALUE
or numbers greater than 2^30.
value
- from which to search for next power of 2public static int align(int value, int alignment)
This method executes without branching. This code is designed to be use in the fast path and should not be used with negative numbers. Negative numbers will result in undefined behaviour.
value
- to be aligned up.alignment
- to be used.public static byte[] fromHexByteArray(byte[] buffer)
buffer
- to convert from a hex representation (in Big Endian)public static byte[] toHexByteArray(byte[] buffer)
buffer
- to convert to a hex representationpublic static byte[] toHexByteArray(byte[] buffer, int offset, int length)
buffer
- to convert to a hex representationoffset
- the offset into the bufferlength
- the number of bytes to convertpublic static byte[] fromHex(java.lang.String string)
string
- to convert from a hex representation (in Big Endian)public static java.lang.String toHex(byte[] buffer, int offset, int length)
buffer
- to convert to a hex representationoffset
- the offset into the bufferlength
- the number of bytes to convertpublic static java.lang.String toHex(byte[] buffer)
buffer
- to convert to a hex representationpublic static boolean isEven(int value)
value
- to check.public static boolean isPowerOfTwo(int value)
value
- to be checked.public static int next(int current, int max)
current
- value to be incremented.max
- value for the cycle.public static int previous(int current, int max)
current
- value to be decremented.max
- value of the cycle.public static int calculateShiftForScale(int scale)
scale
- of the number reported by Unsafe.public static int generateRandomisedId()
Integer.MIN_VALUE
, Integer.MAX_VALUE
] suitable for
use as an Aeron Id.public static boolean isAligned(long address, int alignment)
address
- to be tested.alignment
- boundary the address is tested against.java.lang.IllegalArgumentException
- if the alignment is not a power of 2`Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.