The online racing simulator
LFS External - parsing the flags
I'v hit a snag in my latest project.
Basically, Im experimenting with outgauge, and I cant seem to be able to do anyhting with the Flags.

I can output (and play with) rpm, speed, etc...
but flags... cant do a thing.

To test it, I did a small label, that chances its background color to indicate shift_light on or off.
this is the (not working) code:

if((og.Flags.OG_SHIFTLIGHT))
{
shift_light.BackColor = System.Drawing.Color.Red;
}

That first line (the IF) is where the snag is.
I've tried (og.Flags.XXXX) - but og.Flags apparently only has ToString, Equals, etc...

I cant seem to get a way to see if the og (my outgauge packet) has the OG_Shiftlight flag or not (or for that matter, any other flag).
I know its something retardedly simple, but somehow its been eluding me for quite a while now....

EDIT:
I've managed to make it work, via this line:

if((og.Flags.ToString().Contains(Flags.OutGaugeFlags.OG_SHIFTLIGHT.ToString())))

... but this feels dirty. I feel like using a wreckingball to drive a nail into a wall...
Would it not be...

if ((og.Flags & Flags.OutGaugeFlags.OG_SHIFTLIGHT) == Flags.OutGaugeFlags.OG_SHIFTLIGHT)
{
// Do stuff...
}

Cool that works too, and looks less clumsy.

But I dont QUITE get it. And this is not supposed to be a "it works, dont touch" but a "know why it works, so you can learn" type of project

So.. my questions. Why the single & and not the usual && ?


nvm - TAA has given a link that in 3 mins of quickly skimming yielded the answer:
(which Im gonna type again, just so anyone has the same doubt they can read here, then go read the big article).
the first og.Flags contains the whole flags, lets say
10101010 - lets say the shift light is the 4th from the right.(a "1").
Now, do a bitwise AND (the "&") with the Flags.OutgaugeFlags.OG_SHIFTLIGHT - which is the value for the shiftlight being on. THis should be:
00001000 - as you can see, the 4th digit from the right has a 1, the rest are at zeros.
What the & does is it clears all the info from the positions that have zeroes, and returns the info from the position that has a 1.
In this case, it will bitwise AND the following values (the "x" is whatever value the shiftlight has at a particular moment, 1 or 0:
1010x010
00001000
which will end up equaling = 0000x000 - where the x is the value of the shiftlight at a particular moment.

Pretty simple actually.
Thxs!
Quote from DarkTimes :Would it not be...

if ((og.Flags & Flags.OutGaugeFlags.OG_SHIFTLIGHT) == Flags.OutGaugeFlags.OG_SHIFTLIGHT)
{
// Do stuff...
}


Woah thanks DarkTimes .

FGED GREDG RDFGDR GSFDG