> For the complete documentation index, see [llms.txt](https://docs.zongsoft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zongsoft.com/documentation/en/framework/core/common/bit-vector.md).

# Bit Vector

BitVector32 and BitVector64 bit tag structures.

`BitVector32` and `BitVector64` are used to compress multiple Boolean states into an integer value, suitable for saving low-cost tags such as flag bits, status bits and permission bits.

## Type Relationship

| Type          | Description                                     |
| ------------- | ----------------------------------------------- |
| `BitVector32` | Saves a set of bit tags using a 32-bit integer. |
| `BitVector64` | Saves a set of bit tags using a 64-bit integer. |

## BitVector32 and BitVector64

A bit vector can compress multiple Boolean states into a single integer. The `bit` parameter in the indexer represents a bit mask, not a zero-based sequence number.

Source: [framework/Zongsoft.Core/test/Common/ConvertTest.cs](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/test/Common/ConvertTest.cs#L94) (excerpt; see source for context).

{% code title="ConvertTest.cs" %}

```csharp
public void TestBitVector32()
{
	Zongsoft.Common.BitVector32 vector = 1;

	Assert.Equal(1, vector.Data);
	Assert.True(vector[1]);
	Assert.False(vector[2]);
	Assert.False(vector[3]);
	Assert.False(vector[4]);
	Assert.False(vector[5]);

	vector[5] = true;
	Assert.Equal(5, vector.Data);
	Assert.True(vector[1]);
	Assert.False(vector[2]);
	Assert.False(vector[3]);
	Assert.True(vector[4]);
	Assert.True(vector[5]);
}
```

{% endcode %}

`BitVector64` can be implicitly converted from `BitVector32`, which is suitable for scenarios that require more flag bits.

{% hint style="info" %}
`BitVector32` and `BitVector64` focus more on compact storage; if you want to express a fixed-level encoding, use [HierarchyVector32](/documentation/en/framework/core/common/hierarchy-vector32.md).
{% endhint %}

The above is the original bit vector test of the framework ConvertTest; the numerical value represents the bit mask, and the index parameter cannot be directly understood as a bit sequence number starting from zero. Discussions does not call this structure directly.

## Related Resources

* [BitVector32.cs](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/src/Common/BitVector32.cs)
* [BitVector64.cs](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/src/Common/BitVector64.cs)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zongsoft.com/documentation/en/framework/core/common/bit-vector.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
