mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2025-12-09 16:43:51 +00:00
21 lines
499 B
Plaintext
21 lines
499 B
Plaintext
/**
|
|
* Converts a bitfield to a list of numbers (or words if a wordlist is provided)
|
|
*/
|
|
/proc/bitfield2list(bitfield = NONE, list/wordlist)
|
|
var/list/r = list()
|
|
if(islist(wordlist))
|
|
var/max = min(wordlist.len,16)
|
|
var/bit = 1
|
|
for(var/i=1, i<=max, i++)
|
|
if(bitfield & bit)
|
|
r += wordlist[i]
|
|
bit = bit << 1
|
|
else
|
|
for(var/bit=1, bit<=65535, bit = bit << 1)
|
|
if(bitfield & bit)
|
|
r += bit
|
|
|
|
return r
|
|
|
|
#define IS_VALID_INDEX(list, index) (list.len && index > 0 && index <= list.len)
|