Hello Forum,
I always thought that the simplest way to set a variable to either 0 or 1 was with the XOR function, as in the following snippet:
This way gLight.nStatus can only be set to either 0 or 1 (%LIGHT_ON or %LIGHT_OFF) so it's also a form of data checking. I have used this technique in .DLL's used by other parties.
However, it has been suggested (by the young "bulls") that XOR is old-fashioned and that I should be using in-built functions like IIF() or SWITCH() or even a simple IF..THEN statement, but I can't see why.
Surely XOR is not that hard to understand and (from memory) it relates directly to the assembler command - XOR - and must be very effiecient.
Is there a better way of doing this in PowerBASIC?
Pat
I always thought that the simplest way to set a variable to either 0 or 1 was with the XOR function, as in the following snippet:
Code:
%LIGHT_ON = 0 %LIGHT_OFF = 1 TYPE Lights nStatus as LONG ' Must be either %LIGHT_ON or %LIGHT_OFF END TYPE SUB SetLightStatus( nLightStatus as long ) gLight.nStatus = 0 XOR nLightStatus END SUB ' Usage: SetLightStatus %LIGHT_ON ' Set light status to on ' or SetLightStatus %LIGHT_OFF ' Set light status to off
However, it has been suggested (by the young "bulls") that XOR is old-fashioned and that I should be using in-built functions like IIF() or SWITCH() or even a simple IF..THEN statement, but I can't see why.
Surely XOR is not that hard to understand and (from memory) it relates directly to the assembler command - XOR - and must be very effiecient.
Is there a better way of doing this in PowerBASIC?
Pat
Comment