ee.Array.bitCount

On an element-wise basis, calculates the number of one-bits in the 64-bit two's complement binary representation of the input.
UsageReturns
Array.bitCount()Array
ArgumentTypeDetails
this: inputArrayThe input array.

Examples

Code Editor (JavaScript)

print(ee.Array([], ee.PixelType.int8()).bitCount());  // []

print(ee.Array([0]).bitCount());        // [0]
print(ee.Array([1]).bitCount());        // [1]
print(ee.Array([2]).bitCount());        // [1]
print(ee.Array([3]).bitCount());        // [2]
print(ee.Array([0xFFFF]).bitCount());   // [16]
print(ee.Array([1, 2, 3]).bitCount());  // [1,1,2]

print(ee.Array([[0, 1], [6, 13]]).bitCount());  // [[0,1],[2,3]]

// https://en.wikipedia.org/wiki/Two's_complement signed values.
print(ee.Array([-1]).bitCount());                       // [64]
print(ee.Array([-1], ee.PixelType.int8()).bitCount());  // [64]
print(ee.Array([-2]).bitCount());                       // [63]