Java Utililty Methods Bits Convert to

List of utility methods to do Bits Convert to

Description

The list of methods to do Bits Convert to are organized into topic(s).

Method

intbit(byte[] h, int i)
Get the i'th bit of a byte array.
return (h[i >> 3] >> (i & 7)) & 1;
intbit(int a, int b)
bit
return (a & (1 << b)) >> b;
longbit(int row, int col)
Bitboard containing a single set bit
return 1L << square(row, col);
intBIT(int x)
BIT
return (1 << x);
bytebitArray2byte(boolean[] array)
bit Arraybyte
if (array == null || array.length != 8) {
    throw new RuntimeException("Bad bit array");
byte b = 0;
for (int i = 0; i <= 7; i++) {
    if (array[i]) {
        int nn = (1 << (7 - i));
        b += nn;
...
byte[]bitarrayShiftAndFill(byte[] data, int length, int shift, byte first, byte last)
Shifts data bits left and fills insignificant bits between data bits and next byte boundaries with data from given first and last byte.
byte[] result;
if (shift > ((data.length * 8) - length)) {
    result = new byte[data.length + 1];
    result[0] = (byte) 0x00;
    System.arraycopy(data, 0, result, 1, data.length);
} else {
    result = new byte[data.length];
    System.arraycopy(data, 0, result, 0, data.length);
...
bytebitArrayToByte(byte[] bytes)
bit Array To Byte
byte rtnValue = 0;
final int length = bytes.length;
for (int i = 1; i <= length; i++) {
    final int power = length - i;
    rtnValue += bytes[i - 1] * Math.pow(2, power);
return rtnValue;
StringBitArrayToString(Boolean[] asciiBinary)
Bit Array To String
int index = 0;
String message = "";
int asciiValue = 0;
for (boolean item : asciiBinary) {
    if (item) {
        asciiValue += Math.pow(2, LETTER_BIT_WIDTH - (index % LETTER_BIT_WIDTH) - 1);
    index++;
...
StringbitboardToString(final long l)
Takes a bitboard and returns a 64 character string representation
final String lString = Long.toBinaryString(l);
final byte paddingZeros = (byte) (64 - lString.length());
final StringBuilder b = new StringBuilder(64);
for (byte i = 0; i < paddingZeros; i++) {
    b.append("0");
for (byte i = 0; i < lString.length(); i++) {
    b.append(lString.charAt(i));
...
StringbitboardToString(long bitboard)
Converts a bitboard, not a board, to a string.
String asBinary = Long.toBinaryString(bitboard);
while (asBinary.length() != 64)
    asBinary = "0" + asBinary;
String s = "     a   b   c   d   e   f   g   h\n";
s += "   +---+---+---+---+---+---+---+---+\n 8 | ";
for (int up = 7; up >= 0; up--) {
    for (int out = 0; out < 8; out++) {
        if (asBinary.charAt(63 - (up * 8 + out)) == '1')
...