Name

bitCount - return the number of bits set in a bitfield.

Synopsis

int  bitCount(int  x)
int2 bitCount(int2 x)
int3 bitCount(int3 x)
int4 bitCount(int4 x)

int  bitCount(uint  x)
int2 bitCount(uint2 x)
int3 bitCount(uint3 x)
int4 bitCount(uint4 x)

Parameters

x
Bitfield to count bits in.

Description

Returns the count of set bits (value of 1) in the bitfield x.

Reference Implementation

bitCount for an int bitfield can be implemented like this:

int bitCount(int x)
{
  int i;
  int res = 0;
  for(i = 0; i < 32; i++) {
    mask = 1 << i;
    if (x & mask)
      res ++;
  }
  return res;
}

Profile Support

bitCount is supported in gp5 profiles.

See Also

  http://www.opengl.org/registry/specs/ARB/gpu_shader5.txt

bitfieldExtract, bitfieldInsert, bitfieldReverse, findLSB and findMSB