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\u003enumber.uint16()\u003c/code\u003e casts the input number to an unsigned 16-bit integer, restricting its value range to 0-65535.\u003c/p\u003e\n"],["\u003cp\u003eValues exceeding the maximum are truncated to the maximum (65535), while values below the minimum are set to 0.\u003c/p\u003e\n"],["\u003cp\u003eFloating-point numbers lose their decimal precision when cast to unsigned 16-bit integers.\u003c/p\u003e\n"]]],[],null,["Casts the input value to an unsigned 16-bit integer.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------|---------|\n| Number.uint16`()` | Number |\n\n| Argument | Type | Details |\n|---------------|--------|------------------|\n| this: `input` | Number | The input value. |\n\nExamples\n\nCode Editor (JavaScript) \n\n```javascript\n// Cast a number to unsigned 16-bit integer: [0, 65535].\nvar number = ee.Number(100);\nprint('Number:', number);\n\nvar uint16Number = number.uint16();\nprint('Number cast to uint16:', uint16Number);\n\n\n/**\n * Casting numbers to uint16 that are outside of its range and precision can\n * modify the resulting value, note the behavior of the following scenarios.\n */\n\n// A floating point number cast to uint16 loses decimal precision.\nvar float = ee.Number(1.7);\nprint('Floating point value:', float);\n\nvar floatToUint16 = float.uint16();\nprint('Floating point value cast to uint16:', floatToUint16);\n\n// A number greater than uint16 range max cast to uint16 becomes uint16 range max.\nvar UINT16_MAX = 65535;\nvar outOfRangeHi = ee.Number(UINT16_MAX + 12345);\nprint('Greater than uint16 max:', outOfRangeHi);\n\nvar outOfRangeHiToUint16 = outOfRangeHi.uint16();\nprint('Greater than uint16 max cast to uint16 becomes uint16 max:', outOfRangeHiToUint16);\n\n// A number greater than uint16 range min cast to uint16 becomes uint16 range min.\nvar UINT16_MIN = 0;\nvar outOfRangeLo = ee.Number(UINT16_MIN - 12345);\nprint('Less than uint16 min:', outOfRangeLo);\n\nvar outOfRangeLoToUint16 = outOfRangeLo.uint16();\nprint('Less than uint16 min cast to uint16 becomes uint16 min:', outOfRangeLoToUint16);\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\nColab (Python) \n\n```python\n# Cast a number to unsigned 16-bit integer: [0, 65535].\nnumber = ee.Number(100)\nprint('Number:', number.getInfo())\n\nuint16_number = number.uint16()\nprint('Number cast to uint16:', uint16_number.getInfo())\n\n\n\"\"\"Casting numbers to uint16 that are outside of its range and precision can\nmodify the resulting value, note the behavior of the following scenarios.\n\"\"\"\n\n# A floating point number cast to uint16 loses decimal precision.\nfloat_number = ee.Number(1.7)\nprint('Floating point value:', float_number.getInfo())\n\nfloat_number_to_uint16 = float_number.uint16()\nprint('Floating point value cast to uint16:', float_number_to_uint16.getInfo())\n\n# A number greater than uint16 range max cast to uint16\n# becomes uint16 range max.\nUINT16_MAX = 65535\nout_of_range_hi = ee.Number(UINT16_MAX + 12345)\nprint('Greater than uint16 max:', out_of_range_hi.getInfo())\n\nout_of_range_hi_to_uint16 = out_of_range_hi.uint16()\nprint('Greater than uint16 max cast to uint16 becomes uint16 max:',\n out_of_range_hi_to_uint16.getInfo())\n\n# A number greater than uint16 range min cast to uint16\n# becomes uint16 range min.\nUINT16_MIN = 0\nout_of_range_lo = ee.Number(UINT16_MIN - 12345)\nprint('Less than uint16 min:', out_of_range_lo.getInfo())\n\nout_of_range_lo_to_uint16 = out_of_range_lo.uint16()\nprint('Less than uint16 min cast to uint16 becomes uint16 min:',\n out_of_range_lo_to_uint16.getInfo())\n```"]]