What I meant was:
/*
Name: bitfields.ino
Created: 10/19/2021 8:55:35 AM
Author: KK
*/
struct ChessPieceMove
{
uint16_t side : 1;
uint16_t piece : 3;
uint16_t fromX : 3;
uint16_t fromY : 3;
uint16_t toX : 3;
uint16_t toY : 3;
ChessPieceMove() = delete;
ChessPieceMove(uint16_t move)
{
uint16ToMove(move);
}
void uint16ToMove(uint16_t move)
{
toY = move & 0b111;
toX = (move >> 3) & 0b111;
fromY = (move >> 6) & 0b111;
fromX = (move >> 9) & 0b111;
piece = (move >> 12) & 0b111;
side = (move >> 15) & 0b1;
}
};
void PrintMove(const ChessPieceMove &move)
{
static const char *pieces[] = { "Pawn", "Rook", "Knight", "Bishop", "Queen", "King" };
if (move.piece > 5)
{
Serial.println("Invalid Chess piece");
return;
}
Serial.print(move.side ? "White " : "Black ");
Serial.print(pieces[move.piece]);
Serial.print(" From ");
Serial.print(char(move.fromY + 65));
Serial.print(move.fromX + 1);
Serial.print(" To ");
Serial.print(char(move.toY + 65));
Serial.println(move.toX + 1);
}
// the setup function runs once when you press reset or power the board
void setup()
{
Serial.begin(9600);
}
// the loop function runs over and over again until power down or reset
void loop()
{
ChessPieceMove myMove(random(0u, 65535u));
PrintMove(myMove);
delay(1000);
}