-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
30 lines (26 loc) · 732 Bytes
/
utils.ts
File metadata and controls
30 lines (26 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// util
export function GetTime () {
return Date.now() || 0
}
export class Bitmask {
static IsEnabled (mask: number, position: number) {
return (mask & (1 << position)) > 0
}
static Set (mask: number, position: number, isEnabled: boolean) {
if (position > 30)
throw 'bitmask position cannot be greater than 30'
if (isEnabled)
return mask | (1 << position)
else
return mask & ~(1 << position)
}
static Flip (mask: number, position: number) {
if (!Bitmask.IsEnabled(mask, position))
return Bitmask.Set(mask, position, true)
else
return Bitmask.Set(mask, position, false)
}
static JSON (mask: number) {
return '0b' + mask.toString(2).padStart(8, '0')
}
}