int v = b ? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #1:
As per svick, parsed out conditional operator on separate lines:
int v = b
? (a ? 1 : 2)
: (a ? 0 : 1);
EDIT #2:
Here's one I don't like, but it has no branching whatsoever:
int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #1:
As per svick, parsed out conditional operator on separate lines:
int v = b
? (a ? 1 : 2)
: (a ? 0 : 1);
EDIT #2:
Here's one I don't like, but it has no branching whatsoever:
int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #1:
As per svick , parsed out conditional operator on separate lines:
int v = b
? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #2:
Here's one I don't like, but it has no branching whatsoever:
int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
v = b ? (a ? 1 : 2 ) : (a ? 0 : 1);
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #1:
As per svick , parsed out conditional operator on separate lines:
int v = b
? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #2:
Here's one I don't like, but it has no branching whatsoever:
int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
v = b ? (a ? 1 : 2 ) : (a ? 0 : 1);