Hi All,
I did quite a bit of Google searching, but I’m honestly not even sure what type of Algorithm this would even be called.
Basically, I’m interfacing to a piece of hardware through a .dll which has the following syntax:
Code:
intError = GetHardwareStatus(intStatus)
Depending on the state of the Hardware the The GetHardwareStatus(intStatus) fills intStatus with the Error condition(s) from hardware.
The Hardware datasheet contains the following Error condition map:
Code:
ERROR1 = 1 ;
ERROR2 = 2 ;
ERROR3 = 4 ;
ERROR4 = 8 ;
ERROR5 = 16 ;
ERROR6 = 32 ;
ERROR7 = 64 ;
ERROR8 = 128 ;
ERROR9 = 256;
ERROR10 = 512 ;
Based on the Integer value loaded in intStatus I’m trying to figure out a clever way to determine which Error conditions have been set by hardware.
So for example:
Code:
intError = GetHardwareStatus(intStatus)
loads with an Integer value of 365 which means the hardware has the following error conditions.
Code:
ERROR9 [365-265 = 100]
ERROR7 [100-64=36]
ERROR6 [36-32 = 4]
ERROR3 [4-4=0]
I know I could use an IF/ELSE chain to subtract the ERROR condition from intStatus until I returned a 0 value, but it seems like there should be a more clever way of doing this.
Thanks in advance for your assistance and I apologize if this question has been asked 1000 times before me - I did a search on this forum, but did not find anything.