Using bit arrays

Introduction
Since I like to write tutorials about saving memory, I decided to come up with this tutorial, which teaches you the real meaning of boolean arrays, aswell as bit arrays, and how to use them!

What are boolean arrays?
Boolean arrays look like this:

Code:
new bool:gPlayerArray[MAX_PLAYERS];

However, "bool" is just a predefined tag, "true" and "false" are the values for 1 and 0 respectively, so in reality these arrays can actually hold up to 2,147,483,647 values, just like normal variables. If MAX_PLAYERS is 500, the array above is 2,000 bytes.

There are also "char arrays":

Code:
new bool:gPlayerArray[MAX_PLAYERS char];

The array above is a mere 500 bytes. Still, not bad, but there is still some sparse data left in the array.

Now let's take a bit at bit arrays:

Code:
new BitArray:gPlayerArray<MAX_PLAYERS>;

Believe it or not, the array above is only 29 bytes! Bit arrays use a complex method of packing data into the array, by tightly packing the data into a 1-bit array using specialized bit manipulation, rather than each 4-byte cell (as opposed to regular arrays) or each byte (as opposed to char arrays, I still need clarification on this though).

Let's get started!
You can get y_bit from the latest YSI version here:

http://forum.sa-mp.com/showthread.php?t=321092

You can either use "Bit:" or "BitArray:" to initialize bit arrays:

Code:
new BitArray:gUsingPhone<MAX_PLAYERS>;

These arrays only hold 1-bit values, which are either "true" or "false". Here are a list of relevant functions:

Code:
Bit_Let(BitArray:array<>, slot);

This will set the value in the specified slot to "true".

Code:
Bit_Vet(BitArray:array<>, slot);

This will set the value in the specified slot to "false".

Code:
Bit_Set(BitArray:array<>, slot, bool:value);

This will set the value in the specified slot to "value", which can be either true or false.

Code:
Bit_Get(BitArray:array<>, slot);

Returns either "true" or "false", depending on the value set.

Multiple dimensions
You can also use 2D arrays with these bit arrays:

Code:
new BitArray:gVehicleStreamed[MAX_VEHICLES]<MAX_PLAYERS>;

Setting the value is slightly different, since you need to specify both indices:

Code:
Bit_Let(gVehicleStreamed[vehicleid], playerid, true);

The same goes for the other functions.

Multiple bits
y_bit supports 1 bit arrays, and that's all that you'll probably need. If you feel that you need more bits, you might want to check out "rBits":

http://forum.sa-mp.com/showthread.php?t=275142

It supports 1 bit, as well as 2, 4, 8 and 16 bits (a normal variable is 32 bits).

Conclusion
You've reached the end of this tutorial, that's cool.

The reason why I write these type of tutorials is to point out better methods of saving memory in PAWN, because nobody wants a cluttered, 500 MB AMX file!