Files
Citadel-Station-13-RP/code/__HELPERS/lists/misc.dm
Zandario ed05e01a95 __HELPERS Cleaning and other things I decided to do. (#4584)
* Schizoposting

* The Crungly

* Tabbin' the JSON y'all

* Strings
2022-10-21 01:56:59 -07:00

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)