When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
4 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <stdbool.h>
#include <string.h>
void bytes_to_blocks(const int cols, const int offset, bool blocks[offset*8][cols], const int rows, bool bytes[rows][8]);
//void blocks_to_bytes(const int cols, const int offset, bool blocks[offset*8][cols], const int rows, bool bytes[rows][8]);
int main(void)
{
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");
}
}
return 0;
}
void bytes_to_blocks(const int cols, const int offset, bool blocks[offset*8][cols], const int rows, bool bytes[rows][8])
{
int i=0;
int j=0;
int k=0;
int l=0;
int left=rows;
int row_counter=0;
for (i=0; i<cols; i++)
{
for(j=0; j< offset; j++)
{
for(k=0; k<8; k++)
{
if (left>0)
{
blocks[k + (8*j)][i]=bytes[row_counter][k];
}
else
{
for (l=0; l < (rows % offset); l++)
{
blocks[k + j*8][i]= 0;
}
}
}
row_counter++;
left--;
}
}
}```
!solved
Thank you and let us know if you have any more questions!