Continue to Site

# bit structure for two dimmensional arrays

Status
Not open for further replies.

#### mformazhar1980

##### Junior Member level 1
bit structure for arrays

hi

i am intending to make a bit structure that i am going to use for storing boolean data into a two dimensional array.
the problem is i dont know exactly which data type is suitable so that i could save memory. i have used uint8_t as a data type. all i need to check whether i am on right track or not.

i want to store bits i.e 1's and 0's in a two dimensional array.
is that really save only the bits in said array or is it saving the whole bit in the index?
i.e suppose Value[0][j] stores {1,1,1,1,1}or
Value[1][j] stores {0,0,0,0,0}

the code snippet is as follows
Code:
unit8_t Value[4][10];

typedef struct Save_Bits
{
uint8_t  i  :1;
uint8_t  j  :1;

} Save_Bits;

struct Save_Bits  Value[i][j];

// then in the while loop get values

now the point is that how i can fetch all the data so that it can represent like

Value[0][j] stores all the 0's untill there is 1's appear and then it should immediately switches to Value[1][j] and store all the 1's there until the next change i.e occurrence of 0's again. and switches to Value[2][j] and store all the 0,s there and so on.
can any body help me to sort out the logic.
thanks

[/code]

Re: bit structure for arrays

One possible way to do it would be in a single array of bit counts.

psuedo code:

Code:
uint8_t data[ARRAY_SIZE];
uint8_t index = 0;
uint8_t count = 0;

while(index < ARRAY_SIZE)
{
{
data[index] = ++count;
}

index++;
data[index] = count = 1;

{
data[index] = ++count;
}

index++;
data[index] = count = 1;
}

You could reverse the logic to output the results.

Status
Not open for further replies.