how to trigger carriage return after 8 characters
I would like to have carriage return after 8 characters so it would look like
11111111
11111111
00000000
00000000
instead of
1111111111111111000000000000000000000000000000001111111111111111
I am attempting to make a bit board for chess.
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
int main(){
const unsigned long long board = 18446462598732906495LLU;
std::string binary = std::bitset<64>(board).to_string();
std::cout << std::setw(8);
std::cout.width(8);
std::cout<<binary<<"\n";
return 0;
}//end main
| |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <string>
#include <bitset>
int main()
{
const unsigned short trg_return = 8;
const unsigned long long board = 18446462598732906495LLU;
std::string binary = std::bitset<64>(board).to_string();
for (size_t loop = 0; loop < binary.size(); loop++)
{
std::cout << binary[loop] << ' ';
if (0 == ((loop + 1) % trg_return))
{
std::cout << '\n';
}
}
}
| |
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
|
Thank you for the prompt response!
I am attempting to make a bit board for chess. |
A chess game with one type of piece?
A lot of work IMO, bit math decode and encode and manipulation, just to save a few bytes.
Topic archived. No new replies allowed.