Java Bits Convert to bitboardToString(long bitboard)

Here you can find the source of bitboardToString(long bitboard)

Description

Converts a bitboard, not a board, to a string.

License

Open Source License

Parameter

Parameter Description
bitboard the bitboard to represent as a string.

Return

a string representation of the bitboard.

Declaration

public static String bitboardToString(long bitboard) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w w  w .  j a v  a2  s . c om
     * Converts a <i>bitboard</i>, not a board, to a string. The string will
     * look identical to the result of Board.toString, except that pieces are
     * instead shown as 'X'.
     * 
     * @param bitboard
     *            the bitboard to represent as a string.
     * @return a string representation of the bitboard.
     */
    public static String bitboardToString(long bitboard) {
        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')
                    s += "X | ";
                else
                    s += "  | ";
            }
            s += (up + 1) + "\n   +---+---+---+---+---+---+---+---+";
            if (up != 0)
                s += "\n " + up + " | ";
        }

        s += "\n     a   b   c   d   e   f   g   h\n";
        return s;
    }
}

Related

  1. bitArray2byte(boolean[] array)
  2. bitarrayShiftAndFill(byte[] data, int length, int shift, byte first, byte last)
  3. bitArrayToByte(byte[] bytes)
  4. BitArrayToString(Boolean[] asciiBinary)
  5. bitboardToString(final long l)
  6. bitch(Throwable t)
  7. bitFieldToIndexArray(long bitfield)
  8. bitFieldToString(boolean[] bits)
  9. bitfieldToString(String[] statenames, int value)