Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003e\u003ccode\u003eArray.bitCount()\u003c/code\u003e calculates the number of 1s in the binary representation of each element in an array.\u003c/p\u003e\n"],["\u003cp\u003eIt operates on 64-bit two's complement binary representation, supporting both positive and negative integers.\u003c/p\u003e\n"],["\u003cp\u003eThe function returns an array with the same dimensions as the input, where each element represents the bit count of the corresponding input element.\u003c/p\u003e\n"],["\u003cp\u003eThis method works for arrays of various data types, including int8, int16, int32, and int64.\u003c/p\u003e\n"],["\u003cp\u003eIt handles empty arrays, single-element arrays, multi-dimensional arrays, and arrays with both positive and negative numbers.\u003c/p\u003e\n"]]],["The `bitCount()` function calculates the number of one-bits in the 64-bit two's complement binary representation of each element in an input array. It operates element-wise and returns a new array with the same shape as the input. The input array can contain positive or negative integers, and the output array provides the one-bit count for each corresponding element. For example, `ee.Array([1, 2, 3]).bitCount()` returns `[1, 1, 2]`.\n"],null,["# ee.Array.bitCount\n\nOn an element-wise basis, calculates the number of one-bits in the 64-bit two's complement binary representation of the input.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------|---------|\n| Array.bitCount`()` | Array |\n\n| Argument | Type | Details |\n|---------------|-------|------------------|\n| this: `input` | Array | The input array. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.Array([], ee.PixelType.int8()).bitCount()); // []\n\nprint(ee.Array([0]).bitCount()); // [0]\nprint(ee.Array([1]).bitCount()); // [1]\nprint(ee.Array([2]).bitCount()); // [1]\nprint(ee.Array([3]).bitCount()); // [2]\nprint(ee.Array([0xFFFF]).bitCount()); // [16]\nprint(ee.Array([1, 2, 3]).bitCount()); // [1,1,2]\n\nprint(ee.Array([[0, 1], [6, 13]]).bitCount()); // [[0,1],[2,3]]\n\n// https://en.wikipedia.org/wiki/Two's_complement signed values.\nprint(ee.Array([-1]).bitCount()); // [64]\nprint(ee.Array([-1], ee.PixelType.int8()).bitCount()); // [64]\nprint(ee.Array([-2]).bitCount()); // [63]\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\ndisplay(ee.Array([], ee.PixelType.int8()).bitCount()) # []\n\ndisplay(ee.Array([0]).bitCount()) # [0]\ndisplay(ee.Array([1]).bitCount()) # [1]\ndisplay(ee.Array([2]).bitCount()) # [1]\ndisplay(ee.Array([3]).bitCount()) # [2]\ndisplay(ee.Array([0xFFFF]).bitCount()) # [16]\ndisplay(ee.Array([1, 2, 3]).bitCount()) # [1, 1, 2]\n\ndisplay(ee.Array([[0, 1], [6, 13]]).bitCount()) # [[0, 1], [2, 3]]\n\n# https://en.wikipedia.org/wiki/Two's_complement signed values.\ndisplay(ee.Array([-1]).bitCount()) # [64]\ndisplay(ee.Array([-1], ee.PixelType.int8()).bitCount()) # [64]\ndisplay(ee.Array([-2]).bitCount()) # [63]\n```"]]