Hi there
I know how to solve this problem with brute force, but I like my code to have some elegance so thought I would seek some help. I am not very familiar with bitwise operations so am floundering a little.
A small part of my programme has four checkboxes, labelled $cbImp[1-4]. Rather than store a binary on/off field four times I have used a bitwise operator to store all possible combinations (15) as a number, thusly:
for $item = 1 to 4
if GUICtrlRead($cbImp[$item]) = $GUI_CHECKED then $temp[$item]=2^($item-1)
Next
$Impacts=BitOR($temp[1],$temp[2],$temp[3],$temp[4])
This works well and stores in the database in a single field a number which I can (in my head) read back and restore the checkboxes to their previous state.
However, I can't find an elegant way to handle the 15 combinations (each checkbox being checked or unchecked) [actually it might be 16 - doesn't matter] with a huge case statement or some such.
I know if I read in an odd number it will always mean that $cbImp[1] will be checked. I know a number greater than 8 will mean that $cbImp[4] will be checked, but the middle two numbers look difficult.
Any pointers? (I hope I explained this well enough)