Bitwise
local Bitwise = require("Starlit/utils/Bitwise")
The Bitwise module defines some bitwise operation helper functions. These are generally faster than other implementations I’ve come across.
Functions
-
Starlit.utils.Bitwise.get(int:
integer, pos:integer): (bit:boolean) Gets the value of a specific bit in a number. This is optimised for the case where you only need to check one or two bits: if you want to analyse an entire number, it is far more efficient to convert the number to a binary string instead.
- Parameters:
int (
integer) – The bitwise number.pos (
integer) – Position from the right of the bit to check. The rightmost bit is index 1.
- Returns:
bit (
boolean) – Value of the bit.
-
Starlit.utils.Bitwise.set(int:
integer, pos:integer, value:boolean): (int:integer) Sets the value of a specific bit in a number. If the bit is already set, returns the original number.
- Parameters:
int (
integer) – The bitwise number.pos (
integer) – Position from the right of the bit to check. The rightmost bit is index 1.value (
boolean) – The value to set the bit to.
- Returns:
int (
integer) – The modified number.