Domanda

Hello I have a two dimensional array[8][8], the elements are filled with either 1 or 0. So my question is: How do I convert one whole row into an unsigned integer that is 8 bits long?

I'm coding in C.

È stato utile?

Soluzione

Like this:

int array[8][8]; /* this is what you have */

unsigned row0 = 0;
int i;
for( i = 0; i < 8; i++ ) row0 |= (unsigned)array[0][i] << i;

/* row0 now contains the converted number */

This assumes your data is least-significant-bit first.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top