Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

math.countbits

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static int countbits(int x);

Parameters

Parameter Description
x int value in which to count bits set to 1.

Returns

int Number of bits set to 1 within x.

Description

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.


Declaration

public static int2 countbits(int2 x);

Parameters

Parameter Description
x int2 value in which to count bits for each component.

Returns

int2 int2 containing number of bits set to 1 within each component of x.

Description

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.


Declaration

public static int3 countbits(int3 x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int3 int3 containing number of bits set to 1 within each component of x.

Description

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.


Declaration

public static int4 countbits(int4 x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int4 int4 containing number of bits set to 1 within each component of x.

Description

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.


Declaration

public static int countbits(uint x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int Number of bits set to 1 within x.

Description

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.


Declaration

public static int2 countbits(uint2 x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int2 int2 containing number of bits set to 1 within each component of x.

Description

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.


Declaration

public static int3 countbits(uint3 x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int3 int3 containing number of bits set to 1 within each component of x.

Description

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.


Declaration

public static int4 countbits(uint4 x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int4 int4 containing number of bits set to 1 within each component of x.

Description

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.


Declaration

public static int countbits(ulong x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int Number of bits set to 1 within x.

Description

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.


Declaration

public static int countbits(long x);

Parameters

Parameter Description
x Number in which to count bits.

Returns

int Number of bits set to 1 within x.

Description

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.