Reputation: 43
I'm writing a program in C++, and it has to be as minimal as possible. I need some help with an if/else statement. This is the code:
if (lines & 1 << ((d & 1) * 30 + 5 * l + c)) {
cout << "Invalid";
} else {
lines |= 1 << ((d & 1) * 30 + 5 * l + c);
}
What i'm doing here is: verifing if a bit is set to 1 and I cout something, and if it's not, i'll set it to 1. Is there any way i can combine the 2 lines where i verify and where i set bit to 1 in the if body?
lines & 1 << ((d & 1) * 30 + 5 * l + c)
lines |= 1 << ((d & 1) * 30 + 5 * l + c)
I'm imagining something like:
if (lines |= .... )
And what it should do is: verify if bit is 1 and entering the if body, and if it's not(or it is already) make it 1.
Sorry for my poor english and this stupid request, but i can't figure out a way to do it and it drives me crazy.
P.S: Is there any site/calculator that can give me an boolean formula when i enter an equasion? ex: 3 .. .. = -1. and i need the operand and operator here.
Upvotes: 1
Views: 139