isaacscript-common 5.1.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/functions/bitwise.d.ts +10 -2
- package/functions/bitwise.lua +13 -1
- package/package.json +1 -1
package/functions/bitwise.d.ts
CHANGED
|
@@ -6,8 +6,16 @@
|
|
|
6
6
|
export declare function arrayToBitFlags<T extends BitFlag | BitFlag128>(array: T[] | readonly T[]): BitFlags<T>;
|
|
7
7
|
/** Helper function to convert an array of bits to the resulting decimal number. */
|
|
8
8
|
export declare function convertBinaryToDecimal(bits: int[]): number;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to convert a number to an array of bits.
|
|
11
|
+
*
|
|
12
|
+
* @param number The number to convert.
|
|
13
|
+
* @param minLength Optional. Equal to the minimum amount of bits that should be returned. If the
|
|
14
|
+
* converted number of bits is below this number, 0's will be padded to the left
|
|
15
|
+
* side until the minimum length is met. Default is undefined (which will not cause
|
|
16
|
+
* any padding).
|
|
17
|
+
*/
|
|
18
|
+
export declare function convertDecimalToBinary(number: number, minLength?: int): int[];
|
|
11
19
|
/**
|
|
12
20
|
* Helper function to count the number of bits that are set to 1 in a binary representation of a
|
|
13
21
|
* number.
|
package/functions/bitwise.lua
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__ParseInt = ____lualib.__TS__ParseInt
|
|
3
|
+
local __TS__ArrayUnshift = ____lualib.__TS__ArrayUnshift
|
|
3
4
|
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
4
5
|
local ____exports = {}
|
|
5
6
|
local ____flag = require("functions.flag")
|
|
@@ -18,7 +19,13 @@ function ____exports.convertBinaryToDecimal(self, bits)
|
|
|
18
19
|
return __TS__ParseInt(bitsString, 2)
|
|
19
20
|
end
|
|
20
21
|
--- Helper function to convert a number to an array of bits.
|
|
21
|
-
|
|
22
|
+
--
|
|
23
|
+
-- @param number The number to convert.
|
|
24
|
+
-- @param minLength Optional. Equal to the minimum amount of bits that should be returned. If the
|
|
25
|
+
-- converted number of bits is below this number, 0's will be padded to the left
|
|
26
|
+
-- side until the minimum length is met. Default is undefined (which will not cause
|
|
27
|
+
-- any padding).
|
|
28
|
+
function ____exports.convertDecimalToBinary(self, number, minLength)
|
|
22
29
|
local bits = {}
|
|
23
30
|
local i = 0
|
|
24
31
|
while number > 0 do
|
|
@@ -26,6 +33,11 @@ function ____exports.convertDecimalToBinary(self, number)
|
|
|
26
33
|
number = math.floor(number / 2)
|
|
27
34
|
i = i + 1
|
|
28
35
|
end
|
|
36
|
+
if minLength ~= nil then
|
|
37
|
+
while #bits < minLength do
|
|
38
|
+
__TS__ArrayUnshift(bits, 0)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
29
41
|
return bits
|
|
30
42
|
end
|
|
31
43
|
--- Helper function to count the number of bits that are set to 1 in a binary representation of a
|