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.
Read time 3 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: Unity.Mathematics
- 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.
public static int countbits(int x)
Parameters
int value in which to count bits set to 1.
Returns
Type | Description |
|---|---|
| int | 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.
public static int2 countbits(int2 x)
Parameters
int2 value in which to count bits for each component.
Returns
Type | Description |
|---|---|
| int2 | 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.
public static int3 countbits(int3 x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int3 | 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.
public static int4 countbits(int4 x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int4 | 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.
public static int countbits(uint x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int | 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.
public static int2 countbits(uint2 x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int2 | 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.
public static int3 countbits(uint3 x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int3 | 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.
public static int4 countbits(uint4 x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int4 | 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.
public static int countbits(ulong x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int | 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.
public static int countbits(long x)
Parameters
Number in which to count bits.
Returns
Type | Description |
|---|---|
| int | Number of bits set to 1 within x. |