I have an application where a piece of hardware is going to give my VB.Net program a number to tell me which valves are open. Each valve has a value associated based on 2 to the nth power. So:
Valve01 = 1
Valve02 = 2
Valve03 = 4
Valve04 = 8
Valve05 = 16
etc. (up to 20 Valves)
So, if valves 1, 4 and 5 are open, the number I will get will be 1 + 8 + 16 = 25
I am looking for some help in decoding this so I know which valves are open. For five valves, it is not too difficult as the largest number is 31 but the code would get lengthy when I am looking at 20 valves as the value for the 20th valve alone is 2^19 = 524288.
Dose anyone have a simple way to decode this in VB.net?