bit32.extract

bit32.extract (n: number, f: number, w: number) -> number

Extracts bits of n at position f with a width of w, and returns the resulting integer. w defaults to 1, so a two-argument version of extract returns the bit value at position f. Bits are indexed starting at 0. Errors if f and f+w-1 are not between 0 and 31.

Example

bit32.extract(3.14, 3.14, 3.14)
Raw function spec json
{
  "def": "func",
  "name": "extract",
  "energy": 0,
  "must_use": true,
  "sleep": 0,
  "signatures": [
    {
      "def": "signature",
      "result": [
        {
          "name": "",
          "def": "result",
          "desc": "",
          "variadic": false,
          "type": [
            {
              "def": "simple",
              "value": "number"
            }
          ],
          "optional": false
        }
      ],
      "args": [
        {
          "def": "arg",
          "name": "n",
          "desc": "",
          "type": [
            {
              "def": "simple",
              "value": "number"
            }
          ],
          "variadic": false,
          "optional": false
        },
        {
          "def": "arg",
          "name": "f",
          "desc": "",
          "type": [
            {
              "def": "simple",
              "value": "number"
            }
          ],
          "variadic": false,
          "optional": false
        },
        {
          "def": "arg",
          "name": "w",
          "desc": "",
          "type": [
            {
              "def": "simple",
              "value": "number"
            }
          ],
          "variadic": false,
          "optional": false
        }
      ]
    }
  ],
  "desc": "Extracts bits of `n` at position `f` with `a` width of `w`, and returns the resulting integer.\n`w` defaults to 1, so a two-argument version of extract returns the bit value at position `f`.\nBits are indexed starting at `0`.\nErrors if `f` and `f+w-1` are not between `0` and `31`.",
  "link": "https://luau.org/library#bit32-library#:~:text=function%20bit32.extract",
  "takesSelf": false,
  "private": false
}

< Back to bit32