I have an application that requires me to do some bit masking. The masking will check a string and depending on which bits in that string are high(1) or low(0) enter different methods.
The bits are impotent if they are low(0) and we assume if they are high(1) that everything is ok.
254 = 11111110 in binary. This is the mask I want to use to check the last bit,
void Main()
{
ushort[] data = new ushort[]{254};
int alertPosition = 251;
int tempCriticalPosition = 247;
int fan1FailurePosition = 253;
** int fan2FailurePosition = 254;
int alarmCritialBit = (tempCriticalPosition & data[0]) == 0 ? 0 : 1;
int fan1LedFlag = (fan1FailurePosition & data[0]) == 0 ? 0 : 1;
**int fan2CameraFlag = (fan2FailurePosition & data[0]) == 0 ? 0 : 1;
int alertFlag = (alertPosition & data[0]) == 0 ? 0 : 1;
System.Console.WriteLine(alarmCritialBit);
System.Console.WriteLine(fan1LedFlag);
System.Console.WriteLine(fan2CameraFlag);
System.Console.WriteLine(alertFlag);
}
In this example, that is a fan2Failure. So The data in my array and my bit mask are the same but the result I get is 1. The result I get for doing the other checks is also 1 so I'm confused now as to how this works.
Everything I have looked up on-line recommends a similar approach, I thought that to check my data for a fan2failure I provided in my mask the string for a fan2failure and if the data and my mask where the same it would return 0?
I know this is something simple but i have looked online and cant see what it is I am doing wrong.
Thanks