DEV Community

Tomas Hresko
Tomas Hresko

Posted on

bad output from bytes to block in c

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
Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode

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];
        }
    }

}
Enter fullscreen mode Exit fullscreen mode

Thank you for every advice

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video 🎥

Top comments (0)

Sentry image

Make it make sense

Only the context you need to fix your broken code with Sentry.

Start debugging →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay