# countbits

> Returns number of 1-bits in the binary representation of an int value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Mathematics](/engine/6000.7/script-reference/unity/mathematics.md)
* **Assembly:** UnityEngine.MathematicsModule

## countbits(int)

Returns number of 1-bits in the binary representation of an int value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int countbits(int x)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): int value in which to count bits set to 1.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Number of bits set to 1 within x. |

## countbits(int2)

Returns component-wise number of 1-bits in the binary representation of an int2 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int2 countbits(int2 x)
```

### Parameters

**** (\[int2]\(/engine/6000.7/script-reference/unity/mathematics/int2)): int2 value in which to count bits for each component.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [int2](/engine/6000.7/script-reference/unity/mathematics/int2.md) | int2 containing number of bits set to 1 within each component of x. |

## countbits(int3)

Returns component-wise number of 1-bits in the binary representation of an int3 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int3 countbits(int3 x)
```

### Parameters

**** (\[int3]\(/engine/6000.7/script-reference/unity/mathematics/int3)): Number in which to count bits.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [int3](/engine/6000.7/script-reference/unity/mathematics/int3.md) | int3 containing number of bits set to 1 within each component of x. |

## countbits(int4)

Returns component-wise number of 1-bits in the binary representation of an int4 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int4 countbits(int4 x)
```

### Parameters

**** (\[int4]\(/engine/6000.7/script-reference/unity/mathematics/int4)): Number in which to count bits.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [int4](/engine/6000.7/script-reference/unity/mathematics/int4.md) | int4 containing number of bits set to 1 within each component of x. |

## countbits(uint)

Returns number of 1-bits in the binary representation of a uint value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int countbits(uint x)
```

### Parameters

**** (\[uint]\(https\://learn.microsoft.com/dotnet/api/system.uint32)): Number in which to count bits.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Number of bits set to 1 within x. |

## countbits(uint2)

Returns component-wise number of 1-bits in the binary representation of a uint2 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int2 countbits(uint2 x)
```

### Parameters

**** (\[uint2]\(/engine/6000.7/script-reference/unity/mathematics/uint2)): Number in which to count bits.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [int2](/engine/6000.7/script-reference/unity/mathematics/int2.md) | int2 containing number of bits set to 1 within each component of x. |

## countbits(uint3)

Returns component-wise number of 1-bits in the binary representation of a uint3 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int3 countbits(uint3 x)
```

### Parameters

**** (\[uint3]\(/engine/6000.7/script-reference/unity/mathematics/uint3)): Number in which to count bits.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [int3](/engine/6000.7/script-reference/unity/mathematics/int3.md) | int3 containing number of bits set to 1 within each component of x. |

## countbits(uint4)

Returns component-wise number of 1-bits in the binary representation of a uint4 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int4 countbits(uint4 x)
```

### Parameters

**** (\[uint4]\(/engine/6000.7/script-reference/unity/mathematics/uint4)): Number in which to count bits.

### Returns

| Type                                                              | Description                                                         |
| ----------------------------------------------------------------- | ------------------------------------------------------------------- |
| [int4](/engine/6000.7/script-reference/unity/mathematics/int4.md) | int4 containing number of bits set to 1 within each component of x. |

## countbits(ulong)

Returns number of 1-bits in the binary representation of a ulong value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int countbits(ulong x)
```

### Parameters

**** (\[ulong]\(https\://learn.microsoft.com/dotnet/api/system.uint64)): Number in which to count bits.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Number of bits set to 1 within x. |

## countbits(long)

Returns number of 1-bits in the binary representation of a long value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.

```csharp
public static int countbits(long x)
```

### Parameters

**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): Number in which to count bits.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Number of bits set to 1 within x. |
