# CountBits(int, int)

> Returns the number of bits in a range that are 1.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule

```csharp
public int CountBits(int pos, int numBits = 1)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the bit at which to start searching.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of bits to test. Defaults to 1.

### Returns

| Type                                                       | Description                                       |
| ---------------------------------------------------------- | ------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of bits in a range of bits that are 1. |
