Thanks to all of you who helped with this. I think I've cracked it. Posting this in case anyone else needs to do something similar.
At Phaelax and Scraggle's suggestions, I wrote a few simple functions to set/clear bits. Here's a program showing the functions working, and the functions themselves.
Permissions = 0
do
print("Permissions are: " + str(Permissions))
for iterBit = 0 to 30
printc("Bit " + str(iterBit) + " - ")
printc(str(getbit(Permissions,iterBit)))
if (iterBit < 10)
print(" - key " + chr(iterBit + 48) + " to set, shift+" + chr(iterBit + 48) + " to clear.")
else
print(" - key " + chr(iterBit + 55) + " to set, shift+" + chr(iterBit + 55) + " to clear.")
endif
next iterBit
// Scan number keys to clear/set bits
for iterKey = 48 to 57
if (getrawkeyreleased(iterKey))
if (getrawkeystate(16))
Permissions = clbit(Permissions,iterKey-48)
else
Permissions = stbit(Permissions,iterKey-48)
endif
endif
next iterKey
// Scan alpha keys to clear/set bits
for iterKey = 65 to 85
if (getrawkeyreleased(iterKey))
if (getrawkeystate(16))
Permissions = clbit(Permissions,iterKey-55)
else
Permissions = stbit(Permissions,iterKey-55)
endif
endif
next iterKey
sync()
loop
function stbit(iFlags,iBit)
iFlags = iFlags || (2^iBit)
endfunction iFlags
function clbit(iFlags,iBit)
iFlags = iFlags && (2147483647 - (2^iBit))
endfunction iFlags
function getbit(iFlags,iBit)
bResult = (iFlags && (2^iBit)) > 0
endfunction bResult
Calling stbit() and clbit() will set/clear the appropriate bits of the number without affecting the other bits. Setting an already-set bit does not cause a problem, nor does clearing an already-clear bit.
e.g. Flags = clbit(Flags,0) will clear the right-most bit of Flags.
There's perhaps an easier/faster way to do it than this, but it seems to be working for me at the moment. I also believe that the bits should be labelled 1-31, not 0-30 - but 0-30 worked with the keyboard!
Thanks again to
all of you for your help.
Jambo