是的,如果你用比特做事,你最好使用无符号的。
请注意,unsigned long long
C 标准保证至少为 64 位。
看看位域,在你的情况下非常方便;省去你摆弄&
, |
, ^
, ...
但这里有一个想法:
#include <stdint.h> // Thanks @DoxyLover
typedef struct
{
uint8_t a : 1;
uint8_t b : 1;
uint8_t c : 1;
uint8_t d : 1;
uint8_t e : 1;
uint8_t f : 1;
uint8_t g : 1;
uint8_t h : 1;
} BoardRow;
typedef struct
{
BoardRow r1;
BoardRow r2;
BoardRow r3;
BoardRow r4;
BoardRow r5;
BoardRow r6;
BoardRow r7;
BoardRow r8;
} Board;
void someFunction(void)
{
Board board;
board.r5.d = 1;
...
// You can save these board in uint64_t if you like.
uint64_t savedBoard = (uint64_t)board;
...
}