Hi I can't fix the code to have the output as in example 1. My output is in example 2. Can anyone advise me what I'm doing wrong or where am I wrong? Thank you for every answer
I have no idea what could be wrong I tried a lot of possibilities and still nothing.
int length = 4+1, cols = 3, offset = 2;
bool bytes1[4+1][8] = {
{0,1,0,0,0,0,0,1},
{0,1,1,0,1,0,0,0},
{0,1,1,0,1,1,1,1},
{0,1,1,0,1,0,1,0},
{0,0,0,0,0,0,0,0}
};
bool blocks1[offset*8][cols];
bytes_to_blocks(cols, offset, blocks1, length, bytes1);
for(int j = 0; j < offset*8; j++){
for(int i = 0; i < cols; i++){
printf("%d ", (blocks1[j][i] == true) ? 1 : 0);
}
printf("\n");
if(j % 8 == 7){
printf("\n");
}
}
// prints:
// 0 0 0
// 1 1 1
// 0 1 1
// 0 0 0
// 0 1 1
// 0 0 1
// 0 0 1
// 1 0 1
//
// 0 0 0
// 1 0 0
// 1 0 0
// 0 0 0
// 1 0 0
// 0 0 0
// 1 0 0
// 0 0 0
My output is here
0 0 0
0 1 1
1 0 1
1 0 0
0 0 1
1 0 0
1 0 0
1 1 0
0 0 0
1 0 0
1 0 240
0 0 220
1 0 0
0 0 114
1 0 49
0 0 0
My code is here
void bytes_to_blocks(const int cols, const int offset, bool blocks[offset*8][cols], const int rows, bool bytes[rows][8]) {
int col = 0;
int paragraph = 0;
for(int row = 0; row < rows; row++) {
col++;
if(col > cols) {
col = 0;
paragraph += 8;
}
for (int bit_index = 0; bit_index < 8; bit_index++) {
blocks[paragraph + bit_index][col] = bytes[row][bit_index];
}
}
}
Thank you for every advice
Top comments (0)