Converting a matrix of booleans to a Binary

Hi guys , and girls

I have this boolean matrix;

boolean matrix[8][8]

that stores the some information that will gonna be displayed on a led display;

I read that using the setRow is faster that setLed. (LedControl library)

Anyone knows how to concatenate the "true"s and "false"s of the boolean matrix and convert then to a Binary ?

Example

[true , false, true ,false, true , true, true, true]

1 0 1 0 1 1 1 1

B10101111

lc.setRow(0,2,B10101111);

Thank you!!!

Anyone knows how to concatenate the "true"s and "false"s of the boolean matrix and convert then to a Binary ?

bitSet() comes to mind.

An 8x8 boolean matrix is very wasteful of memory when you could do the same thing in an 8 byte matrix. An advantage of using the byte matrix is it would be ready to pass directly to setRow(). All you need is a function or two to set/read bits and they come in the form of bitSet/bitRead as Paul eluded to.

A series of simple searches and replaces should do the trick quickly and easily!

false with 0
true with 1
space with no-space

etc ...

thank you guys.

gonna change the boolean type to byte.

see ya!

gibrancurtiss:
Anyone knows how to concatenate the "true"s and "false"s of the boolean matrix and convert then to a Binary ?

Example
{true , false, true ,false, true , true, true, true}

{1 0 1 0 1 1 1 1}

B10101111,

Find and replace 'true' with '1'.
Find and replace 'false' with '0'.
Find and replace ',' with '' (null).
Find and replace ' ' (space) with '' (null).
Find and replace '{' with 'B' (or '0b' if you want C style instead of Arduino style).
Find and replace '}' with ','.
A few minor manual tweaks and your huge arrays of booleans (probably 64 bytes each) are now 8-byte arrays of binary.

gibrancurtiss:
thank you guys.

gonna change the boolean type to byte.

That's probably the best way to do it on a microcontroller, just work with bytes and bits from the outset. Much lower memory usage.

If however you do need to change the matrix of boolean into bytes, then the simple code below works fine (example showing converting just one row).

    bool ab[8] = {true,false,false,true,false,false,true,true};  // for example

    byte b=0;
    for (byte k=0; k<8; k++) {
        b <<= 1;
        b |= ab[k];
     }  //  b is now 0x93

thank you guys for your help.
and the code above.

i'm gonna have to change the entire code.

one good night of coding and the problem will be solved!

see ya!