public final class bit extends StaticObject
Byte: 3 2 1 0 | | | | Array: |11110011|10011101|01000000|00101010| | | | | Bit: 23 15 7 0
Modifier and Type | Method and Description |
---|---|
static byte[] |
complement(byte[] data)
Make the two's complement of the given
data array. |
static int |
count(byte value)
Returns the number of one-bits in the given
byte value . |
static int |
count(byte[] data)
Returns the number of one-bits in the given
byte array. |
static byte[] |
flip(byte[] data,
int index)
Flip the bit at the given index.
|
static byte[] |
fromByteString(String data)
Convert a string which was created with the
toByteString(byte...)
method back to an byte array. |
static boolean |
get(byte[] data,
int index)
Return the (boolean) value of the byte array at the given bit index.
|
static byte[] |
increment(byte[] data)
Increment the given
data array. |
static byte[] |
invert(byte[] data)
Invert the given
data array. |
static byte[] |
newArray(int length)
Create a new
byte[] array which can store at least the number
of bits as defined by the given length parameter. |
static byte[] |
newArray(int length,
double p)
Create a new
byte[] array which can store at least the number
of bits as defined by the given length parameter. |
static byte[] |
newBitArray(int length)
Deprecated.
Use
newArray(int) instead. |
static byte[] |
newBitArray(int length,
double p)
Deprecated.
Use
newArray(int, double) instead. |
static byte[] |
set(byte[] data,
int index)
Set the bit in the given byte array at the bit position (not the index
within the byte array) to
true . |
static byte[] |
set(byte[] data,
int index,
boolean value)
Set the bit in the given byte array at the bit position (not the index
within the byte array) to the specified value.
|
static byte[] |
shiftLeft(byte[] data,
int shift)
Shifting all bits in the given
data array the given
shift to the left. |
static byte[] |
shiftRight(byte[] data,
int shift)
Shifting all bits in the given
data array the given
shift to the right. |
static void |
swap(byte[] data,
int start,
int end,
byte[] otherData,
int otherStart)
Swap a given range with a range of the same size with another array.
|
static byte[] |
toByteArray(LargeInteger value)
Deprecated.
Will be removed.
|
static int |
toByteLength(int bitLength)
Return the minimum number of bytes to store the given number of bits.
|
static String |
toByteString(byte... data)
Convert a binary representation of the given byte array to a string.
|
static LargeInteger |
toLargeInteger(byte[] array)
Deprecated.
Will be removed.
|
static byte[] |
unset(byte[] data,
int index)
Set the bit in the given byte array at the bit position (not the index
within the byte array) to
false . |
public static boolean get(byte[] data, int index)
data
- the byte array.index
- the bit index.IndexOutOfBoundsException
- if the index is
index >= max || index < 0
.NullPointerException
- if the data
array is null
.public static byte[] set(byte[] data, int index, boolean value)
data
- the byte array.index
- the bit index within the byte array.value
- the value to set.IndexOutOfBoundsException
- if the index is
index >= max || index < 0
.NullPointerException
- if the data
array is null
.public static byte[] set(byte[] data, int index)
true
.data
- the byte array.index
- the bit index within the byte array.IndexOutOfBoundsException
- if the index is
index >= max || index < 0
.NullPointerException
- if the data
array is null
.public static byte[] unset(byte[] data, int index)
false
.data
- the byte array.index
- the bit index within the byte array.IndexOutOfBoundsException
- if the index is
index >= max || index < 0
.NullPointerException
- if the data
array is null
.public static void swap(byte[] data, int start, int end, byte[] otherData, int otherStart)
start end | | data: +---+---+---+---+---+---+---+---+---+---+---+---+ +---------------+ +---------------+ otherData: +---+---+---+---+---+---+---+---+---+---+---+---+ | otherStart
data
- the first byte array which are used for swapping.start
- the start bit index of the data
byte array,
inclusively.end
- the end bit index of the data
byte array, exclusively.otherData
- the other byte array to swap the elements with.otherStart
- the start index of the otherData
byte array.IndexOutOfBoundsException
- if start > end
or
if start < 0 || end >= data.length*8 || otherStart < 0 ||
otherStart + (end - start) >= otherData.length*8
public static int count(byte[] data)
byte
array.data
- the byte
array for which the one bits should be
counted.byte
array.public static int count(byte value)
byte
value
.value
- the value for which the one bits should be counted.public static byte[] shiftRight(byte[] data, int shift)
data
array the given
shift
to the right. The bits on the left side are filled with
zeros.data
- the data bits to shift.shift
- the number of bits to shift.data
array.NullPointerException
- if the data
array is null
.public static byte[] shiftLeft(byte[] data, int shift)
data
array the given
shift
to the left. The bits on the right side are filled with
zeros.data
- the data bits to shift.shift
- the number of bits to shift.data
array.NullPointerException
- if the data
array is null
.public static byte[] increment(byte[] data)
data
array.data
- the given data
array.data
array.NullPointerException
- if the data
array is null
.public static byte[] invert(byte[] data)
data
array.data
- the given data
array.data
array.NullPointerException
- if the data
array is null
.public static byte[] complement(byte[] data)
data
array.data
- the given data
array.data
array.NullPointerException
- if the data
array is null
.public static byte[] flip(byte[] data, int index)
data
- the data array.index
- the index of the bit to flip.IndexOutOfBoundsException
- if the index is
index >= max || index < 0
.NullPointerException
- if the data
array is null
.@Deprecated public static byte[] toByteArray(LargeInteger value)
LargeInteger
value to an byte array.value
- the value to convert.LargeInteger
.NullPointerException
- if the given value is null
.toLargeInteger(byte[])
@Deprecated public static LargeInteger toLargeInteger(byte[] array)
LargeInteger
.array
- the byte array to convert.LargeInteger
built from the given byte array.toByteArray(LargeInteger)
public static String toByteString(byte... data)
Byte: 3 2 1 0 | | | | Array: "11110011|10011101|01000000|00101010" | | | | Bit: 23 15 7 0Only the array string is printed.
data
- the byte array to convert to a string.fromByteString(String)
public static byte[] fromByteString(String data)
toByteString(byte...)
method back to an byte array.data
- the string to convert.IllegalArgumentException
- if the given data string could not be
converted.toByteString(byte...)
@Deprecated public static byte[] newBitArray(int length)
newArray(int)
instead.byte[]
array which can store at least the number
of bits as defined by the given length
parameter.length
- the number of bits, the returned byte array can store.public static byte[] newArray(int length)
byte[]
array which can store at least the number
of bits as defined by the given length
parameter.length
- the number of bits, the returned byte array can store.@Deprecated public static byte[] newBitArray(int length, double p)
newArray(int, double)
instead.byte[]
array which can store at least the number
of bits as defined by the given length
parameter. The returned
byte array is initialized with ones according to the given ones
probability p
.length
- the number of bits, the returned byte array can store.p
- the ones probability of the returned byte array.IllegalArgumentException
- if p
is not a valid probability.public static byte[] newArray(int length, double p)
byte[]
array which can store at least the number
of bits as defined by the given length
parameter. The returned
byte array is initialized with ones according to the given ones
probability p
.length
- the number of bits, the returned byte array can store.p
- the ones probability of the returned byte array.IllegalArgumentException
- if p
is not a valid probability.public static int toByteLength(int bitLength)
bitLength
- the number of bits© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)