# boolean array question

Noob question, I have an array of 1000 bits that I need to reset periodically, is there a command to do this or do I need to just put it through a for loop?

edit: by "reset" I mean make every bit in the array a 0

Do you have an array of 1000 booleans as the thread title implies or an array of 1000 bits as your question implies ? If it is an array of 1000 bits what data type are the array elements ?

WARNING : You are very likely to short of memory with a 1000 element array.

Stu1987:
Noob question, I have an array of 1000 bits that I need to reset periodically, is there a command to do this or do I need to just put it through a for loop?

edit: by "reset" I mean make every bit in the array a 0

How did you declare this array? `byte myArray[125];` or `boolean myArray[1000];`?

This is important. The first example actually is an array of 1000 bits (125*8=1000). The second example is actually 8000 bits long because the boolean datatype is actually 1 byte (8 bits) long.

Sembazuru:

Stu1987:
Noob question, I have an array of 1000 bits that I need to reset periodically, is there a command to do this or do I need to just put it through a for loop?

edit: by "reset" I mean make every bit in the array a 0

How did you declare this array? `byte myArray[125];` or `boolean myArray[1000];`?

This is important. The first example actually is an array of 1000 bits (125*8=1000). The second example is actually 8000 bits long because the boolean datatype is actually 1 byte (8 bits) long.

Err... I'm actually not quite correct. Add 8 bits to the length of my two examples. I almost forgot about the null byte that is automagically put at the end of the arrays... But, the sizes are correct for the size that one should use...

Edit: Strike that. I was thinking about character arrays, and forgetting that one needs to allocate space for that null when declaring character arrays. Sorry for any confusion.

Sembazuru:
Err... I'm actually not quite correct. Add 8 bits to the length of my two examples. I almost forgot about the null byte that is automagically put at the end of the arrays... But, the sizes are correct for the size that one should use...

Is that something Arduino does? Because I don't believe normal C arrays have a null byte appended at the end.

Yes:

Sembazuru:
Err... I'm actually not quite correct. Add 8 bits to the length of my two examples. I almost forgot about the null byte that is automagically put at the end of the arrays... But, the sizes are correct for the size that one should use...

Is that something Arduino does? Because I don't believe normal C arrays have a null byte appended at the end.

You are right. I was temporarily confused. I've edited my post to acknowledge my error.
(I'm never wrong, just temporarily confused. Just like I'm never lost, just temporarily misplaced... XD)

Sembazuru:

Stu1987:
Noob question, I have an array of 1000 bits that I need to reset periodically, is there a command to do this or do I need to just put it through a for loop?

edit: by "reset" I mean make every bit in the array a 0

How did you declare this array? `byte myArray[125];` or `boolean myArray[1000];`?

This is important. The first example actually is an array of 1000 bits (125*8=1000). The second example is actually 8000 bits long because the boolean datatype is actually 1 byte (8 bits) long.

boolean myArray[1000]; I was unaware boolean took up 8 bits, I guess I should have looked at the reference page... Thanks for the info. That being said, in either scenario is there a way to turn all boolean false and/or all bits to 0?

Not that I'm aware of. If you have that many booleans though it would probably make sense to use bytes and bit operations to access the bits within the bytes. It'll save you some 875 bytes of space.

UKHeliBob:
Do you have an array of 1000 booleans as the thread title implies or an array of 1000 bits as your question implies ? If it is an array of 1000 bits what data type are the array elements ?

WARNING : You are very likely to short of memory with a 1000 element array.

Am I overlooking something here? : 1000 booleans = 8000 bits whick is a kb no? I have 96 kb of SRAM; granted not all of that is usable..

I am going to go with a byte array though, thanks for all your feedback (everyone)
Stu

Stu1987:

UKHeliBob:
Do you have an array of 1000 booleans as the thread title implies or an array of 1000 bits as your question implies ? If it is an array of 1000 bits what data type are the array elements ?

WARNING : You are very likely to short of memory with a 1000 element array.

Am I overlooking something here? : 1000 booleans = 8000 bits whick is a kb no? I have 96 kb of SRAM; granted not all of that is usable..

I am going to go with a byte array though, thanks for all your feedback (everyone)
Stu

When you don't post what hardware you are using, we assume it's an Uno.

Arrch:
When you don't post what hardware you are using, we assume it's an Uno.

Ah, that makes sense.
Noted, thanks.
I'm still in limbo between PLC programming and C++...

Assuming the false state is all bits 0, then memcpy() would be fastest.

I'm not sure, but I think:

``````memset(void *yourArray, int valToSet, size_t bytesToBeSet);
``````

may be even faster than memcpy().

You are right, memset() would be best. memcpy needs a source array - which we don't want in this case.