user2350459 user2350459 - 1 month ago 6
C Question

How do I wrap large lines of bits so it's not one big line?

i'm going to try to make a chess ai, and need long lines of bits(I think, unless someone else has a better method) to represent the pieces positions on the 8x8 board.
It looks like this-

double blackpawns=0b1111111111111111111111111111111111111111111111111111111111111111;


but I would like to make it look like-

double blackpawns=0b11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111;


just so it looks neater. The problem is that if I put any spaces between the 1's, then the 0b only applies to that chunk of ones, and the rest isn't counted, and an error is thrown. Thanks!

btw, I'm not going to have a board full of pawns, I was using that for demonstration.

Answer

That looks not very fine, but consider the following:

#include <stdio.h>
#include <stdint.h>

int main(void)
{
    uint64_t blackpawns = 0b\
11111111\
11111111\
11111111\
11111111\
11111111\
11111111\
11111111\ 
11111111;
        // your code
        return 0;
}

My personal opinion is: it is better to use hexadecimal notation in that case, like:

     uint64_t blackpawns = 0xFFFFFFFFFFFFFFFF;
Comments