I had to accomplish this same task in python, but you can easily take this and turn it into other languages:
def bit_mapper(flag,goal="translate",check_bit=int):
bit_map_dic = {
"0":"Script",
"1":"Account Disabled",
"3":"Home Dir Required",
"4":"Lockout",
"5":"Password Not Required",
"6":"Paswword Can't Change",
"7":"Encrypted Test Password Allowed",
"8":"Temp Duplicate Account",
"9":"Normal Account",
"11":"InterDomain Trust Account",
"12":"WorkStation Trust Account",
"13":"Server Trust Account",
"16":"Don't Expire Password",
"17":"MNS Logon Account",
"18":"Smartcard Required",
"19":"Trusted For Delegation",
"20":"Not Delegated",
"21":"Use DES Key Only",
"22":"Don't Require Preauthorization",
"23":"Password Expired"
}
flag=int(flag)
map="{0:b}".format(flag)
if goal == "translate":
temp = []
for bit in enumerate(map):
if bit[1] is "1":
temp.append(str(bit_map_dic[str(bit[0])]))
return temp
elif goal == "check":
for bit in enumerate(map):
if bit[0] == int(check_bit) and bit[1] is "1":
return True
return False
Two ways to call this function..
1.) If you want to map the Flag to words:
print bit_mapper("513")
2.) Check if a bit is set
print bit_mapper("513",goal="check",check_bit="9")