Search the Community
Showing results for tags 'bitwise operations'.
Found 1 result
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,$temp,$temp,$temp) 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 will be checked. I know a number greater than 8 will mean that $cbImp will be checked, but the middle two numbers look difficult. Any pointers? (I hope I explained this well enough)