docs.unity3d.com
    Show / Hide Table of Contents

    Method countbits

    countbits(Int32)

    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 int countbits(int x)
    Parameters
    Type Name Description
    Int32 x

    int value in which to count bits set to 1.

    Returns
    Type Description
    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.

    Declaration
    public static int2 countbits(int2 x)
    Parameters
    Type Name Description
    int2 x

    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.

    Declaration
    public static int3 countbits(int3 x)
    Parameters
    Type Name Description
    int3 x

    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.

    Declaration
    public static int4 countbits(int4 x)
    Parameters
    Type Name Description
    int4 x

    Number in which to count bits.

    Returns
    Type Description
    int4

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

    countbits(UInt32)

    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 int countbits(uint x)
    Parameters
    Type Name Description
    UInt32 x

    Number in which to count bits.

    Returns
    Type Description
    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.

    Declaration
    public static int2 countbits(uint2 x)
    Parameters
    Type Name Description
    uint2 x

    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.

    Declaration
    public static int3 countbits(uint3 x)
    Parameters
    Type Name Description
    uint3 x

    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.

    Declaration
    public static int4 countbits(uint4 x)
    Parameters
    Type Name Description
    uint4 x

    Number in which to count bits.

    Returns
    Type Description
    int4

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

    countbits(UInt64)

    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(ulong x)
    Parameters
    Type Name Description
    UInt64 x

    Number in which to count bits.

    Returns
    Type Description
    Int32

    Number of bits set to 1 within x.

    countbits(Int64)

    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.

    Declaration
    public static int countbits(long x)
    Parameters
    Type Name Description
    Int64 x

    Number in which to count bits.

    Returns
    Type Description
    Int32

    Number of bits set to 1 within x.

    In This Article
    • countbits(Int32)
    • countbits(int2)
    • countbits(int3)
    • countbits(int4)
    • countbits(UInt32)
    • countbits(uint2)
    • countbits(uint3)
    • countbits(uint4)
    • countbits(UInt64)
    • countbits(Int64)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023