# SetBits

> Sets a range of bits to 0 or 1.

## Definition

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

## SetBits(int, bool, int)

Sets a range of bits to 0 or 1.

```csharp
public void SetBits(int pos, bool value, int numBits)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the first bit to set.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True for 1, false for 0.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of bits to set.

### Remarks

The range runs from index `pos` up to (but not including) `pos + numBits`. No exception is thrown if `pos + numBits` exceeds the length.

## SetBits(int, ulong, int)

Copies bits of a ulong to bits in this array.

```csharp
public void SetBits(int pos, ulong value, int numBits = 1)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the first bit to set.**** (\[ulong]\(https\://learn.microsoft.com/dotnet/api/system.uint64)): Unsigned long from which to copy bits.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of bits to set (must be between 1 and 64).

### Remarks

The destination bits in this array run from index pos up to (but not including) `pos + numBits`. No exception is thrown if `pos + numBits` exceeds the length.

The lowest bit of the ulong is copied to the first destination bit; the second-lowest bit of the ulong is copied to the second destination bit; and so forth.
